Skip to content

Commit 7d2b9dd

Browse files
committed
Configure pytest to use importlib import mode
By default, running `pytest` prepends the source directory to the Python path, since that's where the `tests` package is. That causes Python to import `openslide` from the source directory instead of using the installed copy, and this fails because the source directory doesn't have the compiled extension module. Configure pytest not to change the Python path, as recommended by pytest docs: https://docs.pytest.org/en/7.1.x/explanation/goodpractices.html#choosing-an-import-mode Then, manually set the Python path to allow tests to load common code. Signed-off-by: Benjamin Gilbert <[email protected]>
1 parent 509af98 commit 7d2b9dd

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

.github/workflows/python.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
;;
5454
esac
5555
- name: Install
56-
run: pip install -e .
56+
run: pip install .
5757
- name: Run tests
5858
run: pytest -v
5959
- name: Tile slide

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include *.md
1+
include *.md pytest.ini
22
recursive-include doc *.py *.rst
33
recursive-include examples *.html *.js *.png *.py
44
recursive-include tests *.png *.py *.svs *.tiff

pytest.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[pytest]
2+
minversion = 6.0
3+
# don't try to import openslide from the source directory, since it doesn't
4+
# have the compiled extension module
5+
addopts = --import-mode importlib
6+
# allow tests to import common module
7+
pythonpath = tests

0 commit comments

Comments
 (0)