I thought py.test
is \"standalone\" in a sense that it treats test_*.py
files \"as it is\", and only imports modules specified in these files, with
You can tell pytest to ignore specific files or glob patterns as described here. Put a conftest.py
file in the root directory of your project that lists the files you want pytest
to ignore:
However, many projects will have a setup.py which they don’t want to be imported. Moreover, there may files only importable by a specific python version. For such cases you can dynamically define files to be ignored by listing them in a conftest.py file:
# content of conftest.py import sys collect_ignore = ["setup.py"]
Looks like py.test is using py._path.pyimport
to open your file. If there is a __init__.py
file in the directory, it treats your file as a module, otherwise it opens the file. Long story short, delete the __init__.py
or put your tests in another directory outside your project code (<--- good idea).
http://doc.pylib.org/en/latest/_modules/py/_path/local.html#LocalPath.pyimport
I really suggest you to rename the directory to something not called "distutils". Why ? Because you are overriding an existing module. When "import distutils" or "from distutils import *" appear in the script (from another import or your own python file), it will prefer your directory instead the system one. If the module distutils have been already loaded before, your distutils will not be loaded, because the symbol already exists in global().
It would be really simpler to rename that directory (like tests) instead of trying to fight with py.text / python internals.