Skip to content
Advertisement

Test discovery failure when tests in different directories are called the same

Using py.test, two tests called the same in different directory causes py.test to fail. Why is that? How can I change this without renaming all the tests?

To duplicate do:

JavaScript

Advertisement

Answer

Putting an __init__.py is one way of resolving the conflict. Unlike nose, current pytest does not try to unload test modules in order to import test modules with the same import name. I used to think it’s a bit magic to do this auto-unimporting and might mess up people’s expectation from what the import mechanism does; sometimes people rely on the global state of a test module and with auto-unloading you lose it (a test module importing from another test module might then do unexpected things). But maybe it’s not a practical issue and thus pytest could add a similar hack …

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement