[TIP] adding custom tests to a unittest test run
marius at gedmin.as
Wed May 16 06:27:39 PDT 2012
On Tue, May 15, 2012 at 09:25:28PM -0700, Chris Jerdonek wrote:
> I often have the need to add extra tests to my unittest.main() test
> runs. The tests I need to add are tests that depend on data obtained
> at run-time, e.g. user-provided command-line options.
I'm used to the following idiom for this:
tests = unittest.TestSuite(...)
if __name__ == '__main__':
Although in real life I'll use a test runner (such as zope.testrunner)
that will add up all the tests returned by test_suite() in all of my
test modules, instead of relying on unittest.main().
> I would like to add these tests to unittest.main() in a way that
> doesn't depend on "global state."
I'm not sure I understand this.
> So far, the best I've come up with is the below. Is there a better
> solution? What do others recommend?
> [Also see: https://gist.github.com/2707352 ]
I find this code difficult to understand.
Life was simple before World War II. After that, we had systems.
-- Grace Murray Hopper, 1987
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 198 bytes
Desc: Digital signature
More information about the testing-in-python