How can a user of a library run his own initialization code (setting debug levels of loggers for example) before running tests supplied with the library? Python's unittest
module is used as a testrunner.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
You can try using pytest to run the unittests. If that works (many unittest based test suites work), then you can create a little module, for example "mymod.py", defining a pytest configuration hook:
If you now execute py.test like this:
Then the "mylib" package will be searched for tests and ahead of running them the logging level is modified. The "-p" option specifies a plugin to load and the "--pyargs" tells pytest to try importing the arguments first, instead of treating them as directory or file names (the default).
For more info: http://pytest.org and http://pytest.org/latest/unittest.html
HTH, holger
You could do the set-up work before calling unittest.main.
Or you could subclass the test suite and run a class-level setup method.
Or you could have the test setup incorporate a callback to a user-defined setup method.