New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
__init__
of tests directory is imported twice if the parent is a namespace package
#2541
Comments
Zip file with directory structure: |
With
|
Meanwhile I found the notes under Tests as part of application code and think they may be related. I also found the Is there a way to set the |
@sschwarzer sorry but the short answer is that pytest does not support namespace packages yet. |
also run into this problem when i use namespace package along with absl.flags which does allow one flag defined in 2 modules but because the "evolved import technique" one module is being imported twice with different names and hit this infamous |
Hi everyone, is there any solution to the problem? |
Thank you for pytest! :-)
When running tests in a regular
tests
package inside a namespace package (see PEP 420),tests.__init__
is imported twice.Setup:
Running
pytest
:Note that
imported __init__
is printed twice. I expected it to be printed only once.Indeed when I "convert"
package
to a regular Python package:imported __init__
is only printed once.Between the runs I removed the
__pycache__
directories. This isn't shown here.Of course, this is a simplified example. I think it applies to any case where you have one or more namespace package "above" one or more regular Python packages, which finally contain the
tests
package, i. e.In my project the above behavior leads to some configuration code being executed twice, which results in an exception. For now I can use the workaround of creating the
__init__.py
file in the should-be namespace package.The text was updated successfully, but these errors were encountered: