Skip to content
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

pytest 8.1.1: import file mismatch #219

Open
detrout opened this issue Mar 20, 2024 · 2 comments
Open

pytest 8.1.1: import file mismatch #219

detrout opened this issue Mar 20, 2024 · 2 comments

Comments

@detrout
Copy link

detrout commented Mar 20, 2024

Hello,

I was updating the Debian package for python-graphviz 0.20.2 and was having problems running with pytest 8.1.1.

___ ERROR collecting .pybuild/cpython3_3.11_graphviz/build/tests/conftest.py ___
import file mismatch:
imported module 'conftest' has this __file__ attribute:
  /<<PKGBUILDDIR>>/.pybuild/cpython3_3.11_graphviz/build/tests/backend/conftest.py
which is not the same as the test file we want to collect:
  /<<PKGBUILDDIR>>/.pybuild/cpython3_3.11_graphviz/build/tests/conftest.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules

Debian's test process involves creating a build directory and then running the tests against that supported interpreter versions build directory, so paths are different than just running in the source directory.

As far as I can tell it looks like pytest is getting confused by the existence of two different conftest.py files in tests/ and tests/backends.

I solved the above issue for our build process by moving the contents of tests/backends/conftest.py into tests/conftest.py.

--- a/tests/backend/conftest.py
+++ /dev/null
@@ -1,22 +0,0 @@
-"""pytest fixtures for backend."""
-
-import pytest
-
-
[email protected]
-def mock_run(mocker):
-    yield mocker.patch('subprocess.run', autospec=True)
-
-
[email protected]
-def mock_popen(mocker):
-    yield mocker.patch('subprocess.Popen', autospec=True)
-
-
[email protected]
-def mock_startfile(mocker, platform):
-    if platform == 'windows':
-        kwargs = {'autospec': True}
-    else:
-        kwargs = {'create': True, 'new_callable': mocker.Mock}
-    yield mocker.patch('os.startfile', **kwargs)
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -98,3 +98,21 @@
 def unknown_platform(monkeypatch, name='nonplatform'):
     monkeypatch.setattr('graphviz.backend.viewing.PLATFORM', name)
     yield name
+
[email protected]
+def mock_run(mocker):
+    yield mocker.patch('subprocess.run', autospec=True)
+
+
[email protected]
+def mock_popen(mocker):
+    yield mocker.patch('subprocess.Popen', autospec=True)
+
+
[email protected]
+def mock_startfile(mocker, platform):
+    if platform == 'windows':
+        kwargs = {'autospec': True}
+    else:
+        kwargs = {'create': True, 'new_callable': mocker.Mock}
+    yield mocker.patch('os.startfile', **kwargs)
@xflr6
Copy link
Owner

xflr6 commented Mar 21, 2024

Thanks, see #217 (comment).

AFAIU this is due to pytest-dev/pytest#12123.

'test': ['pytest>=7,<8.1', # https://github.com/pytest-dev/pytest/issues/12123

f1a9f8d

24507fc

@xflr6
Copy link
Owner

xflr6 commented Mar 21, 2024

Made this more visible by mentioning in CHANGES.txt: dbdef1f

https://graphviz.readthedocs.io/en/latest/changelog.html#version-0-20-2

Leaving this open for the moment for visibility.

@xflr6 xflr6 changed the title import file mismatch pytest 8.1.1: import file mismatch Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants