graphviz
graphviz copied to clipboard
pytest 8.1.1: import file mismatch
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)
Thanks, see https://github.com/xflr6/graphviz/issues/217#issuecomment-2003031577.
AFAIU this is due to https://github.com/pytest-dev/pytest/issues/12123.
https://github.com/xflr6/graphviz/blob/78daf45dfa779370c542375995d4e59d86d2c1bd/setup.py#L25
https://github.com/xflr6/graphviz/commit/f1a9f8dd231783ec8200d1565a9fa4febf52c6df
https://github.com/xflr6/graphviz/commit/24507fce3761fb245f063a7a24f0902f03f33836
Made this more visible by mentioning in CHANGES.txt
: dbdef1f105b1924a85c01e37dc851147bab7f2f6
https://graphviz.readthedocs.io/en/latest/changelog.html#version-0-20-2
Leaving this open for the moment for visibility.