-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
BUG: pytest error when loading conftest (seemingly platform-specific) #27806
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
Comments
We could try to downgrade but we should make sure that we don't have the INTERNALERROR raised by pytest. What is weird is that we have windows CI so we should catch such error or maybe this is a Windows 10 error. |
Yes perhaps, my laptop broke down not long ago, and since then I switched from Windows 11 back to Windows 10. With Windows 11 I have never seen such error, though I'm not sure what version of
@glemaitre Does this mean that I need to do some extra tests (and in particular how)? |
@glemaitre Does this mean that I need to do some extra tests (and in particular how)? I need to go back to #26371, and check that downgrading does not raise the INTERNALERROR. |
My suggestions:
Just to make sure I read your issue correctly between the lines for you |
True, and I think it is because there is no
Suggestion 1. Yes it works! Suggestion 2. I did see that comment, but I did not realize that @glemaitre It seems that there is no need for downgrading now, but do you think we should add a note or something in the documentation in case someone else runs into this issue in the future? |
Just curious, how do you install the scikit-learn development version:
I would say solution 3 (moving |
Iβm using the second one. And yes I agree that solution 3 is simplest, and it does solve the issue at least on my machine. Iβm just a bit afraid that there are some magics of using nested conftests. But after all Iβm not really familiar with these stuff, so if you donβt think it will cause future problems Iβm +1 for it @lesteve. |
Just for future reference could you show what is the value of The quickest way to do it would be to edit the files below and add a print statement or write into a file if somehow pytest captures the stdout or maybe some other tricks if you can find better ones ... I am particularly interested in this part of the stack-trace:
and in particular:
|
@lesteve This is how I modified the Code def _importconftest(
self, conftestpath: Path, importmode: Union[str, ImportMode], rootpath: Path
) -> types.ModuleType:
print()
print(f"_importconftest({conftestpath=}, {importmode=}, {rootpath=})")
existing = self.get_plugin(str(conftestpath))
if existing is not None:
return cast(types.ModuleType, existing)
pkgpath = resolve_package_path(conftestpath)
if pkgpath is None:
_ensure_removed_sysmodule(conftestpath.stem)
try:
mod = import_path(conftestpath, mode=importmode, root=rootpath)
except Exception as e:
assert e.__traceback__ is not None
exc_info = (type(e), e, e.__traceback__)
raise ConftestImportFailure(conftestpath, exc_info) from e
self._check_non_top_pytest_plugins(mod, conftestpath)
self._conftest_plugins.add(mod)
dirpath = conftestpath.parent
print(f" {mod=}")
print(f" {dirpath=}, {self._dirpath2confmods=}")
if dirpath in self._dirpath2confmods:
print(f" Iterating over self._dirpath2confmods")
for path, mods in self._dirpath2confmods.items():
print(f" {path=}, {mods=}")
if dirpath in path.parents or path == dirpath:
assert mod not in mods, f"{mod} should not be in {mods}"
mods.append(mod)
self.trace(f"loading conftestmodule {mod!r}")
self.consider_conftest(mod)
return mod This is what happens on the main branch when running Printout
TracebackTraceback (most recent call last):
File "D:\Downloads\mambaforge\envs\sklearn-env\Scripts\pytest-script.py", line 9, in <module>
sys.exit(console_main())
File "D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\_pytest\config\__init__.py", line 192, in console_main
code = main()
File "D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\_pytest\config\__init__.py", line 150, in main
config = _prepareconfig(args, plugins)
File "D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\_pytest\config\__init__.py", line 331, in _prepareconfig
config = pluginmanager.hook.pytest_cmdline_parse(
File "D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\pluggy\_hooks.py", line 493, in __call__
return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
File "D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\pluggy\_manager.py", line 115, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\pluggy\_callers.py", line 130, in _multicall
teardown[0].send(outcome)
File "D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\_pytest\helpconfig.py", line 104, in pytest_cmdline_parse
config: Config = outcome.get_result()
File "D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\pluggy\_result.py", line 114, in get_result
raise exc.with_traceback(exc.__traceback__)
File "D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\pluggy\_callers.py", line 77, in _multicall
res = hook_impl.function(*args)
File "D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\_pytest\config\__init__.py", line 1081, in pytest_cmdline_parse
self.parse(args)
File "D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\_pytest\config\__init__.py", line 1431, in parse
self._preparse(args, addopts=addopts)
File "D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\_pytest\config\__init__.py", line 1333, in _preparse
self.hook.pytest_load_initial_conftests(
File "D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\pluggy\_hooks.py", line 493, in __call__
return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
File "D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\pluggy\_manager.py", line 115, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\pluggy\_callers.py", line 152, in _multicall
return outcome.get_result()
File "D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\pluggy\_result.py", line 114, in get_result
raise exc.with_traceback(exc.__traceback__)
File "D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\pluggy\_callers.py", line 77, in _multicall
res = hook_impl.function(*args)
File "D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\_pytest\config\__init__.py", line 1159, in pytest_load_initial_conftests
self.pluginmanager._set_initial_conftests(
File "D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\_pytest\config\__init__.py", line 563, in _set_initial_conftests
self._try_load_conftest(anchor, importmode, rootpath)
File "D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\_pytest\config\__init__.py", line 585, in _try_load_conftest
self._getconftestmodules(x, importmode, rootpath)
File "D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\_pytest\config\__init__.py", line 609, in _getconftestmodules
mod = self._importconftest(conftestpath, importmode, rootpath)
File "D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\_pytest\config\__init__.py", line 660, in _importconftest
assert mod not in mods, f"{mod} should not be in {mods}"
AssertionError: <module 'sklearn.conftest' from 'd:\\ossd\\scikit-learn-yxiao\\sklearn\\conftest.py'> should not be in [<module 'conftest' from 'D:\\ossd\\scikit-learn-yxiao\\conftest.py'>, <module 'sklearn.conftest' from 'd:\\ossd\\scikit-learn-yxiao\\sklearn\\conftest.py'>] This is what happens when running Printout
Traceback
This is what happens when running pytest printout
|
FYI we managed to reproduce the issue with @fcharras on his Windows VM. Hopefully we will manage to make a reproducer for pytest-dev/pytest#9765. |
Reopening because the issue is still under investigation even if #27954 improves the situation a bit. |
Closing, this is fixed now in Pytest 8.1.0 see pytest-dev/pytest#11708, also we are moving away from setuptools. |
Describe the bug
I'm seeing errors on my Windows machine when running
pytest
(does not work with onlypytest
, and does not work for directories that hasconftest.py
). This seems to be a platform-specific problem, since CI is not complaining. I investigated a bit and found pytest-dev/pytest#9765, but it doesn't look likepytest
is planning to fix it, at least for now. I tried downgrading topytest==7.0.1
and everything worked smoothly, but in #26373 the minimum version ofpytest
has already been7.1.2
for scikit-learn (due to some CI errors forpytest==5.x.x
), so scikit-learn is raising error:scikit-learn/sklearn/conftest.py
Lines 30 to 34 in 5c4288d
I'm wondering if it is possible to pin
pytest==7.0.1
or at least relax the minimum requirement a bit toPYTEST_MIN_VERSION = "7.0.1"
? Or are there any other suggestions how I may resolve this issue? @glemaitre who bumped the minimum version ofpytest
to 7.1.2. Truly sorry for the inconvenience caused by my annoying Windows machine.Steps/Code to Reproduce
or
Running
pytest
on a single file works correctly.Expected Results
No error is thrown.
Actual Results
For the first example,
For the second example,
Versions
The text was updated successfully, but these errors were encountered: