Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Closed
Charlie-XIAO opened this issue Nov 19, 2023 · 12 comments Β· Fixed by #27954 or #27963
Closed

BUG: pytest error when loading conftest (seemingly platform-specific) #27806

Charlie-XIAO opened this issue Nov 19, 2023 · 12 comments Β· Fixed by #27954 or #27963
Labels

Comments

@Charlie-XIAO
Copy link
Contributor

Charlie-XIAO commented Nov 19, 2023

Describe the bug

I'm seeing errors on my Windows machine when running pytest (does not work with only pytest, and does not work for directories that has conftest.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 like pytest is planning to fix it, at least for now. I tried downgrading to pytest==7.0.1 and everything worked smoothly, but in #26373 the minimum version of pytest has already been 7.1.2 for scikit-learn (due to some CI errors for pytest==5.x.x), so scikit-learn is raising error:

if parse_version(pytest.__version__) < parse_version(PYTEST_MIN_VERSION):
raise ImportError(
f"Your version of pytest is too old. Got version {pytest.__version__}, you"
f" should have pytest >= {PYTEST_MIN_VERSION} installed."
)

I'm wondering if it is possible to pin pytest==7.0.1 or at least relax the minimum requirement a bit to PYTEST_MIN_VERSION = "7.0.1"? Or are there any other suggestions how I may resolve this issue? @glemaitre who bumped the minimum version of pytest to 7.1.2. Truly sorry for the inconvenience caused by my annoying Windows machine.

Steps/Code to Reproduce

pytest

or

pytest sklearn/utils/tests

Running pytest on a single file works correctly.

Expected Results

No error is thrown.

Actual Results

For the first example,

❯ pytest
Traceback (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 1075, in pytest_cmdline_parse
    self.parse(args)
  File "D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\_pytest\config\__init__.py", line 1425, in parse
    self._preparse(args, addopts=addopts)
  File "D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\_pytest\config\__init__.py", line 1327, 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 1153, 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 654, in _importconftest
    assert mod not in mods
AssertionError

For the second example,

❯ pytest sklearn/utils/tests
================================================================== test session starts ===================================================================
platform win32 -- Python 3.9.18, pytest-7.4.3, pluggy-1.3.0
rootdir: D:\ossd\scikit-learn-yxiao
configfile: setup.cfg
plugins: cov-4.1.0
collected 1957 items / 1 error

========================================================================= ERRORS =========================================================================
____________________________________________________ ERROR collecting sklearn/utils/tests/conftest.py ____________________________________________________
D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\_pytest\runner.py:341: in from_call
    result: Optional[TResult] = func()
D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\_pytest\runner.py:372: in <lambda>
    call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\_pytest\doctest.py:560: in collect
    module = self.config.pluginmanager._importconftest(
D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\_pytest\config\__init__.py:654: in _importconftest
    assert mod not in mods
E   AssertionError
================================================================ short test summary info =================================================================
ERROR sklearn/utils/tests/conftest.py - AssertionError
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================== 1 warning, 1 error in 1.43s ===============================================================

Versions

❯ python -c "import sklearn; sklearn.show_versions()"

System:
    python: 3.9.18 | packaged by conda-forge | (main, Aug 30 2023, 03:40:31) [MSC v.1929 64 bit (AMD64)]
executable: D:\Downloads\mambaforge\envs\sklearn-env\python.exe
   machine: Windows-10-10.0.19045-SP0

Python dependencies:
      sklearn: 1.4.dev0
          pip: 23.2.1
   setuptools: 68.2.2
        numpy: 1.26.0
        scipy: 1.11.2
       Cython: 3.0.2
       pandas: 2.1.1
   matplotlib: 3.8.0
       joblib: 1.3.2
threadpoolctl: 3.2.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: mkl
    num_threads: 6
         prefix: libblas
       filepath: D:\Downloads\mambaforge\envs\sklearn-env\Library\bin\libblas.dll
        version: 2022.1-Product
threading_layer: intel

       user_api: openmp
   internal_api: openmp
    num_threads: 12
         prefix: vcomp
       filepath: D:\Downloads\mambaforge\envs\sklearn-env\vcomp140.dll
        version: None
@Charlie-XIAO Charlie-XIAO added Bug Needs Triage Issue requires triage labels Nov 19, 2023
@glemaitre
Copy link
Member

I'm wondering if it is possible to pin pytest==7.0.1 or at least relax the minimum requirement a bit to PYTEST_MIN_VERSION = "7.0.1"

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.

@Charlie-XIAO
Copy link
Contributor Author

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 pytest I had by then. But in pytest-dev/pytest#9765 seems that some Linux users were also having this error, so really weird.

We could try to downgrade but we should make sure that we don't have the INTERNALERROR raised by pytest.

@glemaitre Does this mean that I need to do some extra tests (and in particular how)?

@glemaitre
Copy link
Member

@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.

@lesteve
Copy link
Member

lesteve commented Nov 22, 2023

My suggestions:

  • just in case try whether python -m pytest sklearn/utils/tests avoids the issue
  • try whether pytest --pyargs sklearn.utils.tests avoids the issue (seems like --pyargs is mentioned as a work-around in Regression in 7.1 ? Windows CI started to fail with "assert mod not in mods" since 7.1Β pytest-dev/pytest#9765)
  • Can you try moving the content of sklearn/utils/tests/conftest.py to sklearn/conftest.py and deleting sklearn/utils/tests/conftest.py? This could be a simple work-around that is acceptable for us to merge if that works. I think this is the only conftest.py we have outside sklearn/conftest.py and doc/conftest.py ...

Just to make sure I read your issue correctly between the lines for you pytest sklearn/manifold/tests does work fine, i.e. there is something special with sklearn/utils/tests?

@Charlie-XIAO
Copy link
Contributor Author

Just to make sure I read your issue correctly between the lines for you pytest sklearn/manifold/tests does work fine, i.e. there is something special with sklearn/utils/tests?

True, and I think it is because there is no conftest.py under sklearn/manifold/tests/.

My suggestions:

  • just in case try whether python -m pytest sklearn/utils/tests avoids the issue
  • try whether pytest --pyargs sklearn.utils.tests avoids the issue (seems like --pyargs is mentioned as a work-around in Regression in 7.1 ? Windows CI started to fail with "assert mod not in mods" since 7.1Β pytest-dev/pytest#9765)
  • Can you try moving the content of sklearn/utils/tests/conftest.py to sklearn/conftest.py and deleting sklearn/utils/tests/conftest.py? This could be a simple work-around that is acceptable for us to merge if that works. I think this is the only conftest.py we have outside sklearn/conftest.py and doc/conftest.py ...

Suggestion 1. Yes it works! Suggestion 2. I did see that comment, but I did not realize that --pyargs should be used like this, so I did something wrong. But indeed this one also solves the issue. Suggestion 3. Works as well, but given the previous two solutions I think this may not be necessary anymore. Thank you so much @lesteve!

@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?

@lesteve
Copy link
Member

lesteve commented Nov 22, 2023

Just curious, how do you install the scikit-learn development version:

  • python setup.py develop
  • pip install -e . --no-build-isolation (possibly with some slight variation)
  • something else?

I would say solution 3 (moving sklearn/utils/tests/conftest.py to sklearn/conftest.py) if it works is the simplest work-around to avoid this issue.

@Charlie-XIAO
Copy link
Contributor Author

Charlie-XIAO commented Nov 22, 2023

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.

@glemaitre glemaitre removed the Needs Triage Issue requires triage label Nov 22, 2023
@lesteve
Copy link
Member

lesteve commented Dec 13, 2023

Just for future reference could you show what is the value of mod and mods in the Assertion assert mod not in mods in your pytest first example (i.e. pytest without mentioning a path):

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:

  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 654, in _importconftest
    assert mod not in mods

and in particular:

  • values of contestpath, importmode, rootpath
  • values of mod and mods

@Charlie-XIAO
Copy link
Contributor Author

@lesteve This is how I modified the pytest code:

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 pytest on the main branch:

Printout

_importconftest(conftestpath=WindowsPath('D:/ossd/scikit-learn-yxiao/conftest.py'), importmode='prepend', rootpath=WindowsPath('D:/ossd/scikit-learn-yxiao'))
   mod=<module 'conftest' from 'D:\\ossd\\scikit-learn-yxiao\\conftest.py'>
   dirpath=WindowsPath('D:/ossd/scikit-learn-yxiao'), self._dirpath2confmods={}

_importconftest(conftestpath=WindowsPath('D:/ossd/scikit-learn-yxiao/sklearn/conftest.py'), importmode='prepend', rootpath=WindowsPath('D:/ossd/scikit-learn-yxiao'))
   mod=<module 'sklearn.conftest' from 'd:\\ossd\\scikit-learn-yxiao\\sklearn\\conftest.py'>
   dirpath=WindowsPath('D:/ossd/scikit-learn-yxiao/sklearn'), self._dirpath2confmods={}

_importconftest(conftestpath=WindowsPath('D:/ossd/scikit-learn-yxiao/conftest.py'), importmode='prepend', rootpath=WindowsPath('D:/ossd/scikit-learn-yxiao'))

_importconftest(conftestpath=WindowsPath('D:/ossd/scikit-learn-yxiao/sklearn/conftest.py'), importmode='prepend', rootpath=WindowsPath('D:/ossd/scikit-learn-yxiao'))
   mod=<module 'sklearn.conftest' from 'd:\\ossd\\scikit-learn-yxiao\\sklearn\\conftest.py'>
   dirpath=WindowsPath('D:/ossd/scikit-learn-yxiao/sklearn'), self._dirpath2confmods={WindowsPath('D:/ossd/scikit-learn-yxiao/sklearn'): [<module 'conftest' from 'D:\\ossd\\scikit-learn-yxiao\\conftest.py'>, <module 'sklearn.conftest' from 'd:\\ossd\\scikit-learn-yxiao\\sklearn\\conftest.py'>]}
   Iterating over self._dirpath2confmods
        path=WindowsPath('D:/ossd/scikit-learn-yxiao/sklearn'), mods=[<module 'conftest' from 'D:\\ossd\\scikit-learn-yxiao\\conftest.py'>, <module 'sklearn.conftest' from 'd:\\ossd\\scikit-learn-yxiao\\sklearn\\conftest.py'>]
Traceback

Traceback (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 pytest sklearn on the main branch:

Printout

_importconftest(conftestpath=WindowsPath('D:/ossd/scikit-learn-yxiao/conftest.py'), importmode='prepend', rootpath=WindowsPath('D:/ossd/scikit-learn-yxiao'))
   mod=<module 'conftest' from 'D:\\ossd\\scikit-learn-yxiao\\conftest.py'>
   dirpath=WindowsPath('D:/ossd/scikit-learn-yxiao'), self._dirpath2confmods={}

_importconftest(conftestpath=WindowsPath('D:/ossd/scikit-learn-yxiao/sklearn/conftest.py'), importmode='prepend', rootpath=WindowsPath('D:/ossd/scikit-learn-yxiao'))
   mod=<module 'sklearn.conftest' from 'd:\\ossd\\scikit-learn-yxiao\\sklearn\\conftest.py'>
   dirpath=WindowsPath('D:/ossd/scikit-learn-yxiao/sklearn'), self._dirpath2confmods={}

_importconftest(conftestpath=WindowsPath('D:/ossd/scikit-learn-yxiao/conftest.py'), importmode='prepend', rootpath=WindowsPath('D:/ossd/scikit-learn-yxiao'))

_importconftest(conftestpath=WindowsPath('D:/ossd/scikit-learn-yxiao/sklearn/conftest.py'), importmode='prepend', rootpath=WindowsPath('D:/ossd/scikit-learn-yxiao'))
   mod=<module 'sklearn.conftest' from 'd:\\ossd\\scikit-learn-yxiao\\sklearn\\conftest.py'>
   dirpath=WindowsPath('D:/ossd/scikit-learn-yxiao/sklearn'), self._dirpath2confmods={WindowsPath('D:/ossd/scikit-learn-yxiao/sklearn'): [<module 'conftest' from 'D:\\ossd\\scikit-learn-yxiao\\conftest.py'>, <module 'sklearn.conftest' from 'd:\\ossd\\scikit-learn-yxiao\\sklearn\\conftest.py'>]}
   Iterating over self._dirpath2confmods
        path=WindowsPath('D:/ossd/scikit-learn-yxiao/sklearn'), mods=[<module 'conftest' from 'D:\\ossd\\scikit-learn-yxiao\\conftest.py'>, <module 'sklearn.conftest' from 'd:\\ossd\\scikit-learn-yxiao\\sklearn\\conftest.py'>]
Traceback

Traceback (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 pytest sklearn/utils/tests on the main branch (the above two examples directly raise, while this example captures the error when collecting tests):

pytest printout

_importconftest(conftestpath=WindowsPath('D:/ossd/scikit-learn-yxiao/conftest.py'), importmode='prepend', rootpath=WindowsPath('D:/ossd/scikit-learn-yxiao'))
================================================================== test session starts ===================================================================
platform win32 -- Python 3.9.18, pytest-7.4.3, pluggy-1.3.0
rootdir: D:\ossd\scikit-learn-yxiao
configfile: setup.cfg
plugins: cov-4.1.0
collected 1972 items / 1 error

========================================================================= ERRORS =========================================================================
____________________________________________________ ERROR collecting sklearn/utils/tests/conftest.py ____________________________________________________
D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\_pytest\runner.py:341: in from_call
    result: Optional[TResult] = func()
D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\_pytest\runner.py:372: in <lambda>
    call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\_pytest\doctest.py:560: in collect
    module = self.config.pluginmanager._importconftest(
D:\Downloads\mambaforge\envs\sklearn-env\lib\site-packages\_pytest\config\__init__.py:660: in _importconftest
    assert mod not in mods, f"{mod} should not be in {mods}"
E   AssertionError: <module 'sklearn.utils.tests.conftest' from 'd:\\ossd\\scikit-learn-yxiao\\sklearn\\utils\\tests\\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'>, <module 'sklearn.utils.tests.conftest' from 'd:\\ossd\\scikit-learn-yxiao\\sklearn\\utils\\tests\\conftest.py'>]
-------------------------------------------------------------------- Captured stdout ---------------------------------------------------------------------

_importconftest(conftestpath=WindowsPath('D:/ossd/scikit-learn-yxiao/sklearn/utils/tests/conftest.py'), importmode='prepend', rootpath=WindowsPath('D:/ossd/scikit-learn-yxiao'))
   mod=<module 'sklearn.utils.tests.conftest' from 'd:\\ossd\\scikit-learn-yxiao\\sklearn\\utils\\tests\\conftest.py'>
   dirpath=WindowsPath('D:/ossd/scikit-learn-yxiao/sklearn/utils/tests'), self._dirpath2confmods={WindowsPath('D:/ossd/scikit-learn-yxiao/sklearn/utils/tests'): [<module 'conftest' from 'D:\\ossd\\scikit-learn-yxiao\\conftest.py'>, <module 'sklearn.conftest' from 'd:\\ossd\\scikit-learn-yxiao\\sklearn\\conftest.py'>, <module 'sklearn.utils.tests.conftest' from 'd:\\ossd\\scikit-learn-yxiao\\sklearn\\utils\\tests\\conftest.py'>], WindowsPath('D:/ossd/scikit-learn-yxiao'): [<module 'conftest' from 'D:\\ossd\\scikit-learn-yxiao\\conftest.py'>]}
   Iterating over self._dirpath2confmods
        path=WindowsPath('D:/ossd/scikit-learn-yxiao/sklearn/utils/tests'), mods=[<module 'conftest' from 'D:\\ossd\\scikit-learn-yxiao\\conftest.py'>, <module 'sklearn.conftest' from 'd:\\ossd\\scikit-learn-yxiao\\sklearn\\conftest.py'>, <module 'sklearn.utils.tests.conftest' from 'd:\\ossd\\scikit-learn-yxiao\\sklearn\\utils\\tests\\conftest.py'>]
================================================================ short test summary info =================================================================
ERROR sklearn/utils/tests/conftest.py - AssertionError: <module 'sklearn.utils.tests.conftest' from 'd:\\ossd\\scikit-learn-yxiao\\sklearn\\utils\\tests\\conftest.py'> should not be in [<mod...
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================== 1 warning, 1 error in 1.58s ===============================================================

@lesteve
Copy link
Member

lesteve commented Dec 13, 2023

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.

@lesteve
Copy link
Member

lesteve commented Dec 13, 2023

Reopening because the issue is still under investigation even if #27954 improves the situation a bit.

@lesteve
Copy link
Member

lesteve commented May 30, 2024

Closing, this is fixed now in Pytest 8.1.0 see pytest-dev/pytest#11708, also we are moving away from setuptools.

@lesteve lesteve closed this as completed May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants