0

I have a fairly complex system that I want to test using python. My test code will interact with the system using a Python module I've already written. There are a few things however, that I haven't been able to figure out, regarding the testing framework. I haven't selected one yet, but obviously I feel directed to unittest.

  1. Passing parameters to the tests. I need to pass a specific ID to many different parts of my test code, depending on which component of the system I am testing. Does unittest provide for this? In other words, right now I just have a test script, which I run like this: ./testscript.py 123 win 32 How can I pass the same parameters similarly in a testing framework?

  2. unittest provides for setUp() and tearDown() methods, but they are called before/after each test method. How can I have functions that are called before/after the entire battery of tests in a TestCase?

Maybe unittest is not what I actually want to use?

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328

2 Answers2

1

As for #2, it seems that setUpClass() and tearDownClass() are designed for this. The documentation even shows an example of using it to createExpensiveConnectionObject().

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
1

I use tox to run my tests across multiple configurations. Some of my unittests skip certain tests if an optional module isn't there, which means I needed a check to make sure that the module detection code works. Tox doesn't have an easy way to specify any command-line arguments, so the easiest solution was to go through an environment variable.

F.C.'s pointer to python, unittest: is there a way to pass command line options to the app applies if you decide that extra arguments are the way to go.

Community
  • 1
  • 1
Andrew Dalke
  • 14,889
  • 4
  • 39
  • 54