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?

4
  • 3
    for #1 see this stackoverflow.com/questions/1029891/… it can be done Commented Dec 14, 2011 at 16:29
  • Thanks F.C. that makes logical sense. I'm assuming the only way to actually get parameters to the modules I'm testing with then are globals. Commented Dec 14, 2011 at 20:17
  • So shall I accept my own answer, or would you like to make that an answer so I can accept it? Commented Dec 15, 2011 at 0:18
  • you could add the solution from that answer to yours and accept it in case someone comes here looking for a solution Commented Dec 15, 2011 at 13:36

2 Answers 2

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().

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.