Unittest interpreter restart
I have an interesting testing scenario and I'm hoping some fellow PyCharmers can help!
A module I'm testing performs dynamic imports (searches through directories and imports modules found within them).
One test case imports modules found in DirectoryA. Another test case imports modules found in DiretoryB. Each test case verifies the appropriate number of modules are found. Whichever test is run second will fail because modules the previous test are still kicking around.
Is there a way to specify that a particular test should require an new invocation of the Python interpreter?
For reference, I'm using unittest in Pycharm 2016.2
Thanks!
Please sign in to leave a comment.
Hello.
It is not possible, but you can create separate run configurations for each test, pack them on "compound" and launch it. Each test in this case will be started in separate tab and separate interpreter.
Or you can unload your module (http://stackoverflow.com/questions/437589/how-do-i-unload-reload-a-python-module) in tear down (https://docs.python.org/2/library/unittest.html#test-cases)
Ilya - thanks for the reply. I know how to create run configs for each step but could you describe (or send a pointer) to your comment
'pack them on "compound" and launch it'.
I've tried unloading the modules but I just can't seem to unravel all the dependencies. As usual, this is a testing-only problem, and not something my application uses will face in the real world :)
Thanks!
Hello,
Here is screenshot about compund config:
Ilya, thank you very much for the pointer. That worked great. Now I eager keep my fingers crossed a "sync" option gets added to compound tests so that they can be run one at a time :)
Cheers!