For reference, this is the opposite of this question. That question asks how to get pytest to use your local module. I want to avoid pytest using the local module.
I need to test my module's installation procedure. We should all be testing our modules' installation procedures. Therefore, I want my test suite to pretend like it's any other python module trying to import my module, which I have installed (whether or not it's up to date with my latest edits and/or an editable install is my business).
My project layout looks like this:
.
├── my_package
│ ├── __init__.py
│ └── my_module.py
├── setup.py
├── pyproject.toml
└── tests
├── conftest.py
├── __init__.py
└── test_my_package.py
If I
pip install .
cd tests
python -c "import my_package"
it all works. However, if I
pip install .
pytest
it does not. This is because pytest automatically adds the calling directory to the PYTHONPATH
, making it impossible to test that pip install
has worked. I want it to not do that.
I need to do this because I am using setuptools-scm
(which has different behaviour in editable and non-editable installs) and setuptools.find_packages
, which makes it easy to ignore subpackages. However, to reiterate, my issue is with pytest's discovery, not with the use of these two utilities.