Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Pytest suddenly cannot find module #3789
Hello. I use pytest on a CI server to test our software. We have been using pytest for years but with the latest update we have an error importing a module during pytest. My logic behind isolating this issue to pytest is: on the CI server, nothing has changed (same python, same code, same OS image) the updated version of pytest is the only thing that has changed.
original versions of what pytest passed with
current versions where I get failures:
Let's say the module that cannot import is called X. When within the directory of X, (where the _UnitTest directory is) running pytest allows all of the tests to pass. Changing directory back one layer (or anywhere outside of the X directory), now those tests from module X fail because the import statement failed.
Also on macOS I had all of the tests passing with pytest 3.6.3. Upgraded pytest, and now the tests related to module X fail. Many other modules import and work however module X does not. I have debugged a lot of it, and all of the paths look good, but it still fails to import. I'm not exactly sure what sets module X apart from the other dozens of module we use successfully.
I hope this makes sense and I can elaborate more if needed. I am not working in a virtualenv but I can put full pip lists in the comments if more is needed other then the versions I gave above.
I do know that it stems from my init file in that module. That is where the import statement is, which is where the error occurs. (all of my other modules that pass have an init like this as well)
@Agi-dev do you have any method to reproduce?
Sorry, I've tried to reproduce it with simple example with no success despite the fact I've found a way to make my tests work again.
Here is a way to reproduce the problem:
Make a directory structure such as
the output is
It seems there is a problem when mixing directories of tests with packages of tests. Note that there is no mention of dir1_2 in the output. I saw this starting with 3.7.0. I do not see the issue with 3.6.4.
pushed a commit
Aug 10, 2018
Not sure why this was closed, the PR still doesn't fix my problem. Sorry I wasn't able to get back to you right away it was a busy week. I'll post the traceback below.
I run a normal pytest, and I'm told that the module radiation_pressure cannot be found. It gets to the init file which has from radiation_pressure import *. And it bugs out there. I posted the link to our software above.