Skip to content

Commit 2f45722

Browse files
committed
Fix C extension import in CI tests
The C extension was being built but not imported during tests due to Python's sys.path ordering. The project root directory was appearing first in sys.path, causing Python to import from the source directory (which doesn't have the compiled .so file) instead of the installed package in site-packages. Changes: - Add pytest --import-mode=importlib to prevent pytest from adding the project root to sys.path, ensuring tests import from the installed package in the tox virtualenv - Add MAXMINDDB_REQUIRE_EXTENSION=1 to the "Setup test suite" step to ensure the extension is built during CI setup
1 parent cc8e760 commit 2f45722

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
- name: Setup test suite
3333
run: tox run -vv --notest --skip-missing-interpreters false
3434
env:
35+
MAXMINDDB_REQUIRE_EXTENSION: 1
3536
TOX_GH_MAJOR_MINOR: ${{ matrix.env }}
3637
- name: Run test suite
3738
run: tox run --skip-pkg-install

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ ignore = [
9090
"setup.py" = ["ALL"]
9191
"tests/*" = ["ANN201", "D"]
9292

93+
[tool.pytest.ini_options]
94+
# Use importlib mode to prevent pytest from adding the project root to sys.path.
95+
# This ensures tests import from the tox virtualenv's installed package (which includes
96+
# the compiled C extension) rather than directly from the source directory (which doesn't
97+
# have the .so file). We still test the source code, just via the installed version.
98+
addopts = "--import-mode=importlib"
99+
93100
[tool.tox]
94101
env_list = [
95102
"3.10",

0 commit comments

Comments
 (0)