pytest icon indicating copy to clipboard operation
pytest copied to clipboard

Regression in 7.1 ? Windows CI started to fail with "assert mod not in mods" since 7.1

Open Carreau opened this issue 3 years ago • 17 comments

Now sorry I know this is not a minimal reproducer, but I just want to log this here, and will investigate later:

You can see one Failure here

ERROR collecting test session 
C:\hostedtoolcache\windows\Python\3.9.10\x64\lib\site-packages\_pytest\runner.py:338: in from_call
    result: Optional[TResult] = func()
C:\hostedtoolcache\windows\Python\3.9.10\x64\lib\site-packages\_pytest\runner.py:369: in <lambda>
    call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
C:\hostedtoolcache\windows\Python\3.9.10\x64\lib\site-packages\_pytest\main.py:7[23](https://github.com/ipython/ipython/runs/5535021197?check_suite_focus=true#step:8:23): in collect
    for x in self._collectfile(pkginit):
C:\hostedtoolcache\windows\Python\3.9.10\x64\lib\site-packages\_pytest\main.py:575: in _collectfile
    ihook = self.gethookproxy(fspath)
C:\hostedtoolcache\windows\Python\3.9.10\x64\lib\site-packages\_pytest\main.py:539: in gethookproxy
    my_conftestmodules = pm._getconftestmodules(
C:\hostedtoolcache\windows\Python\3.9.10\x64\lib\site-packages\_pytest\config\__init__.py:579: in _getconftestmodules
    mod = self._importconftest(conftestpath, importmode, rootpath)
C:\hostedtoolcache\windows\Python\3.9.10\x64\lib\site-packages\_pytest\config\__init__.py:6[24](https://github.com/ipython/ipython/runs/5535021197?check_suite_focus=true#step:8:24): in _importconftest
    assert mod not in mods
E   AssertionError

Now I'm not sure what this does, but my quick understanding is that it checks whether conftest.py itself is not in the list of collected modules ? We might definitely do something wrong on IPython side, but it's strange as other non-windows CI are passing and regardless of whether this is something I did wrong, can the assert get an explanation messages as second argument ?

Downgrading to <7.1 fixes the issue.

Again I'll try to get a MVP/small example, but it may take me some time, and I guessed maybe one of you will immediately know why this is happening.

  • [ ] a detailed description of the bug or problem you are having
  • [ ] output of pip list from the virtual environment you are using
  • [ ] pytest and operating system versions
  • [ ] minimal example if possible

Carreau avatar Mar 14 '22 10:03 Carreau

Thanks for the report, I will take a look when I get a chance. 7.1 had some internal conftest refactorings. If you manage to provide a reproduction that'd be great.

bluetech avatar Mar 14 '22 10:03 bluetech

One thing that seems somewhat suspicious is how IPython's pytest_ipdoctest.py seems to have some custom code around importing conftest files:

https://github.com/ipython/ipython/blob/d7cc335a36cdfe4159c9b88c94311866c923a547/IPython/testing/plugin/pytest_ipdoctest.py#L635-L646

The-Compiler avatar Mar 14 '22 10:03 The-Compiler

Yeah, it might be something on our end, we have to do some pretty weird things seeing we also an interpreter. So I would not be surprised if the problem is from our plugins.

Carreau avatar Mar 14 '22 11:03 Carreau

It does seem like removing the plugin fixes the issue, I'm not quite sure why it's windows only, and I haven't written it, so I'm not sure how I can fix it.

Feel free to close, worse case I'll run the plugin only on linux CI.

Carreau avatar Mar 14 '22 11:03 Carreau

Not sure if it helps, I know it's not a slim repro setup, but this repo was just pinned to <7.1 because it was consistently reproducible in there: https://github.com/compas-dev/compas

gonzalocasas avatar Mar 14 '22 15:03 gonzalocasas

Seeing same in statsmodels on Windows.

https://dev.azure.com/statsmodels/statsmodels-testing/_build/results?buildId=4410&view=logs&j=9c2ba6b6-9ef1-5300-06cd-4db9cc34ebf3&t=f07685ef-4dee-5864-e861-bb3b9ab4fc6b

bashtage avatar Mar 18 '22 17:03 bashtage

@gonzalocasas and @bashtage I see both your CI install IPython in them, could you try pinning IPython to <8 to see if it's a problem with the IPython doctest plugin itself (that should not be present in 7.x)

Carreau avatar Mar 18 '22 17:03 Carreau

@Carreau I get the same error when I pip install ipython<8. I also get the same error when I pip uninstall ipython. Works find with 7.0.x, broken in 7.1.x.

bashtage avatar Mar 20 '22 22:03 bashtage

I can also get this error when I reun specific tests:

 ValueError: Plugin already registered: c:\git\statsmodels\statsmodels\conftest.py=<module 'statsmodels.conftest' from 'c:\\git\\statsmodels\\statsmodels\\conftest.py'>

bashtage avatar Mar 20 '22 22:03 bashtage

I've got the same error, but on linux! Can't run any test on 7.1.x, reverting back to 7.0.x fixes the issue:

root@f786a0bfb51b:/srv/vidicenter# pytest -n4
WARNING No rollbar access token provided
Traceback (most recent call last):
  File "/usr/local/bin/pytest", line 8, in <module>
    sys.exit(console_main())
  File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 187, in console_main
    code = main()
  File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 145, in main
    config = _prepareconfig(args, plugins)
  File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 324, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "/usr/local/lib/python3.8/dist-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/usr/local/lib/python3.8/dist-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/usr/local/lib/python3.8/dist-packages/pluggy/_callers.py", line 55, in _multicall
    gen.send(outcome)
  File "/usr/local/lib/python3.8/dist-packages/_pytest/helpconfig.py", line 102, in pytest_cmdline_parse
    config: Config = outcome.get_result()
  File "/usr/local/lib/python3.8/dist-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/usr/local/lib/python3.8/dist-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 1016, in pytest_cmdline_parse
    self.parse(args)
  File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 1304, in parse
    self._preparse(args, addopts=addopts)
  File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 1206, in _preparse
    self.hook.pytest_load_initial_conftests(
  File "/usr/local/lib/python3.8/dist-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/usr/local/lib/python3.8/dist-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/usr/local/lib/python3.8/dist-packages/pluggy/_callers.py", line 60, in _multicall
    return outcome.get_result()
  File "/usr/local/lib/python3.8/dist-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/usr/local/lib/python3.8/dist-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 1083, in pytest_load_initial_conftests
    self.pluginmanager._set_initial_conftests(
  File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 532, in _set_initial_conftests
    self._try_load_conftest(current, namespace.importmode, rootpath)
  File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 551, in _try_load_conftest
    self._getconftestmodules(x, importmode, rootpath)
  File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 575, in _getconftestmodules
    mod = self._importconftest(conftestpath, importmode, rootpath)
  File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 620, in _importconftest
    assert mod not in mods
AssertionError

jgb avatar Apr 08 '22 08:04 jgb

FYI: I also get this in an rpmbuild of asdf for openSUSE Linux. I attribute it to some import mismatch for the conftest.py installed into the sitelib.

Fails:

Have asdf installed in sitelib but collect from asdf in source directory. This worked with pytest < 7

[    3s] Executing(%check): /usr/bin/bash -e /var/tmp/rpm-tmp.cC3tTE
[    3s] + umask 022
[    3s] + cd /home/abuild/rpmbuild/BUILD
[    3s] + cd asdf-2.11.1
[    3s] + export LANG=en_US.UTF-8
[    3s] + LANG=en_US.UTF-8
[    3s] + export PY_IGNORE_IMPORTMISMATCH=1
[    3s] + PY_IGNORE_IMPORTMISMATCH=1
[    3s] ++ '[' -f _current_flavor ']'
[    3s] ++ cat _current_flavor
[    3s] + last_flavor=python38
[    3s] + '[' -z python38 ']'
[    3s] + '[' python38 '!=' python39 ']'
[    3s] + '[' -d build ']'
[    3s] + mv build _build.python38
[    3s] + '[' -d _build.python39 ']'
[    3s] + mv _build.python39 build
[    3s] + echo python39
[    3s] + python_flavor=python39
[    3s] + PYTHONDONTWRITEBYTECODE=1
[    3s] + pytest-3.9 --ignore=_build.python39 --ignore=_build.python310 --ignore=_build.python38 -v --remote-data=none
[    3s] Internet access disabled
[    3s] ============================= test session starts ==============================
[    3s] platform linux -- Python 3.9.12, pytest-7.1.1, pluggy-1.0.0 -- /usr/bin/python3.9
[    3s] cachedir: .pytest_cache
[    3s] rootdir: /home/abuild/rpmbuild/BUILD/asdf-2.11.1, configfile: setup.cfg, testpaths: asdf, docs
[    3s] plugins: asdf-2.11.1, sugar-0.9.4, openfiles-0.5.0, doctestplus-0.12.0, remotedata-0.3.2
[    4s] collecting ... collected 0 items / 1 error
[    4s] 
[    4s] ==================================== ERRORS ====================================
[    4s] ________________________ ERROR collecting test session _________________________
[    4s] /usr/lib/python3.9/site-packages/_pytest/runner.py:338: in from_call
[    4s]     result: Optional[TResult] = func()
[    4s] /usr/lib/python3.9/site-packages/_pytest/runner.py:369: in <lambda>
[    4s]     call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
[    4s] /usr/lib/python3.9/site-packages/_pytest/main.py:723: in collect
[    4s]     for x in self._collectfile(pkginit):
[    4s] /usr/lib/python3.9/site-packages/_pytest/main.py:575: in _collectfile
[    4s]     ihook = self.gethookproxy(fspath)
[    4s] /usr/lib/python3.9/site-packages/_pytest/main.py:539: in gethookproxy
[    4s]     my_conftestmodules = pm._getconftestmodules(
[    4s] /usr/lib/python3.9/site-packages/_pytest/config/__init__.py:575: in _getconftestmodules
[    4s]     mod = self._importconftest(conftestpath, importmode, rootpath)
[    4s] /usr/lib/python3.9/site-packages/_pytest/config/__init__.py:620: in _importconftest
[    4s]     assert mod not in mods
[    4s] E   AssertionError
[    4s] =========================== short test summary info ============================
[    4s] ERROR  - AssertionError
[    4s] !!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
[    4s] =============================== 1 error in 0.29s ===============================
[    4s] error: Bad exit status from /var/tmp/rpm-tmp.cC3tTE (%check)

Works:

move the asdf source directory away and directly test with --pyargs asdf

[    3s] Executing(%check): /usr/bin/bash -e /var/tmp/rpm-tmp.wVMB1t
[    3s] + umask 022
[    3s] + cd /home/abuild/rpmbuild/BUILD
[    3s] + cd asdf-2.11.1
[    3s] + export LANG=en_US.UTF-8
[    3s] + LANG=en_US.UTF-8
[    3s] + mv asdf asdf.moved
[    3s] ++ '[' -f _current_flavor ']'
[    3s] ++ cat _current_flavor
[    3s] + last_flavor=python38
[    3s] + '[' -z python38 ']'
[    3s] + '[' python38 '!=' python39 ']'
[    3s] + '[' -d build ']'
[    3s] + mv build _build.python38
[    3s] + '[' -d _build.python39 ']'
[    3s] + mv _build.python39 build
[    3s] + echo python39
[    3s] + python_flavor=python39
[    3s] + PYTHONDONTWRITEBYTECODE=1
[    3s] + pytest-3.9 --ignore=_build.python39 --ignore=_build.python310 --ignore=_build.python38 -v --pyargs asdf --remote-data=none
[    3s] Internet access disabled
[    3s] ============================= test session starts ==============================
[    3s] platform linux -- Python 3.9.12, pytest-7.1.1, pluggy-1.0.0 -- /usr/bin/python3.9
[    3s] cachedir: .pytest_cache
[    3s] rootdir: /home/abuild/rpmbuild/BUILD/asdf-2.11.1, configfile: setup.cfg
[    3s] plugins: asdf-2.11.1, sugar-0.9.4, openfiles-0.5.0, doctestplus-0.12.0, remotedata-0.3.2
[    5s] collecting ... collected 721 items
[    5s] 
[    5s] asdf.py::asdf.asdf.AsdfFile.make_reference PASSED                        [  0%]
...
[  200s] ============ 691 passed, 8 skipped, 22 xfailed in 196.36s (0:03:16) ==========

bnavigator avatar Apr 26 '22 12:04 bnavigator

Any chance this can be related to finding multiple conftest.py? This was working for us in linux on 7.0.1 and no longer working in 7.1.1. When we hackily removed conf files so that only one could be found, the issue went away.

So we've reverted and are pinning pytest to 7.0.1 for now.

Would be great to see this fixed, or provide a migration path for how to deal with it in 7.1.0. We are in a monorepo, and use the pytest runner for the entire repo (at the root). Has never been an issue in the past.

chebee7i avatar May 11 '22 21:05 chebee7i

Any chance this can be related to finding multiple conftest.py?

This could very well be the case. I had a colleague who had the same issue on Windows. It turned out to be triggered by him creating his the conda test environment as a subfolder inside the test folder (Not recommended)

So pytest was picking up an extra conftest.py file from the numpy folder in site-packages/ (numpy ships it tests files with the module)

melund avatar Jul 04 '22 08:07 melund

Just to add to this, the error occurs in my repo (issue 162) even when conda is set up properly (not as a subfolder like @melund describes). My repo only has a single conftest.py too. Leads me to believe this issue is happening in conda environments where installed dependencies also have conftest.py files. Maybe pytest is incorrectly grabbing conftest files from package dependencies. Is it that a possibility?

jacksund avatar Jul 04 '22 14:07 jacksund

conftests are only ever searched locally, so unless you put evil magic in your tests folders you shouldnt see this

RonnyPfannschmidt avatar Jul 04 '22 15:07 RonnyPfannschmidt

lol good to know. I must have done some evil magic without realizing it :sweat_smile:

jacksund avatar Jul 04 '22 15:07 jacksund

The issue is reproducible only when the IPython installed via pip<21.3 (first good commit https://github.com/pypa/pip/commit/e5be3f796e710301052afb7839acb6c7b471e3dd), so it might be just because of IPython's pyproject.toml

Kojoley avatar Sep 04 '22 02:09 Kojoley

Hello,

just an update to say that this issue still exists, on linux, with pytest 7.2.0. Can anything be done about this? I have a single conftest.py in my root folder, and then several smaller conftest.py in subfolders for specific modules. This has always worked in pytest < 7.1.0. Am I doing something wrong? Or is this a bug that could be fixed?

Greetings,

jgb

jgb avatar Oct 26 '22 08:10 jgb

For our case, the issue was in symlinks which we created inside site-packages directory. We switched to --pyargs (python -m pytest --pyargs nextgisweb instead of python -m pytest package/nextgisweb/nextgisweb) and now everything works well.

dezhin avatar Oct 30 '22 11:10 dezhin

@bluetech any news on this? Anything newer than pytest 7.0.1 is still broken for me on linux, including the latest 7.2.1. I've got one conftest.py in my root, and several smaller conftest.py in subfolders for different django apps. This works fine in 7.0.1 and before, but fails to run at all in any newer version, with the following output:

Traceback (most recent call last):
  File "/usr/local/bin/pytest", line 8, in <module>
    sys.exit(console_main())
  File "/usr/local/lib/python3.10/dist-packages/_pytest/config/__init__.py", line 190, in console_main
    code = main()
  File "/usr/local/lib/python3.10/dist-packages/_pytest/config/__init__.py", line 148, in main
    config = _prepareconfig(args, plugins)
  File "/usr/local/lib/python3.10/dist-packages/_pytest/config/__init__.py", line 329, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "/usr/local/lib/python3.10/dist-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/usr/local/lib/python3.10/dist-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/usr/local/lib/python3.10/dist-packages/pluggy/_callers.py", line 55, in _multicall
    gen.send(outcome)
  File "/usr/local/lib/python3.10/dist-packages/_pytest/helpconfig.py", line 103, in pytest_cmdline_parse
    config: Config = outcome.get_result()
  File "/usr/local/lib/python3.10/dist-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/usr/local/lib/python3.10/dist-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/usr/local/lib/python3.10/dist-packages/_pytest/config/__init__.py", line 1058, in pytest_cmdline_parse
    self.parse(args)
  File "/usr/local/lib/python3.10/dist-packages/_pytest/config/__init__.py", line 1346, in parse
    self._preparse(args, addopts=addopts)
  File "/usr/local/lib/python3.10/dist-packages/_pytest/config/__init__.py", line 1248, in _preparse
    self.hook.pytest_load_initial_conftests(
  File "/usr/local/lib/python3.10/dist-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/usr/local/lib/python3.10/dist-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/usr/local/lib/python3.10/dist-packages/pluggy/_callers.py", line 60, in _multicall
    return outcome.get_result()
  File "/usr/local/lib/python3.10/dist-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/usr/local/lib/python3.10/dist-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/usr/local/lib/python3.10/dist-packages/_pytest/config/__init__.py", line 1125, in pytest_load_initial_conftests
    self.pluginmanager._set_initial_conftests(
  File "/usr/local/lib/python3.10/dist-packages/_pytest/config/__init__.py", line 560, in _set_initial_conftests
    self._try_load_conftest(current, namespace.importmode, rootpath)
  File "/usr/local/lib/python3.10/dist-packages/_pytest/config/__init__.py", line 579, in _try_load_conftest
    self._getconftestmodules(x, importmode, rootpath)
  File "/usr/local/lib/python3.10/dist-packages/_pytest/config/__init__.py", line 603, in _getconftestmodules
    mod = self._importconftest(conftestpath, importmode, rootpath)
  File "/usr/local/lib/python3.10/dist-packages/_pytest/config/__init__.py", line 648, in _importconftest
    assert mod not in mods
AssertionError

jgb avatar Jan 19 '23 09:01 jgb

I am consistently seeing this on windows with https://github.com/strawberry-graphql/strawberry, python 3.10, pytest 7.3. Must be something with my machine, since CI passes for that project, but I have to pin pytest to 7.0 for local development.

kristjanvalur avatar May 27 '23 09:05 kristjanvalur

Is the issue here that we haven't provided enough information to reproduce the issue? Or that this isn't deemed a serious enough issue? Or something else?

The title of this issue should be amended so that it is not indicating this is a Windows only issue. This issue also impacts linux.

chebee7i avatar May 30 '23 15:05 chebee7i

The assertion needs to get a message, lets add a Bugfix that shows The Module name

RonnyPfannschmidt avatar May 30 '23 15:05 RonnyPfannschmidt

What would the required change be to get more information? I can always do a local change.

kristjanvalur avatar May 30 '23 15:05 kristjanvalur

You can at least change assert mod not in mods to assert mod not in mods, f"{mod} seem to be loaded twice.".

Carreau avatar May 30 '23 16:05 Carreau

, f"{mod} seem to be loaded twice."

In my case, I get this: AssertionError: <module 'tests.conftest' from 'E:\\git\\strawberry\\tests\\conftest.py'> seem to be loaded twice.

Note, this happens only when using the "tests" tab of VS code, and refreshing tests. running pytest from the terminal works fine.

Here's the full stack trace:

File "C:\Users\kristjan\AppData\Local\pypoetry\Cache\virtualenvs\strawberry-graphql-TghffK6u-py3.7\lib\site-packages\_pytest\config\__init__.py", line 1067, in pytest_cmdline_parse
    self.parse(args)
  File "C:\Users\kristjan\AppData\Local\pypoetry\Cache\virtualenvs\strawberry-graphql-TghffK6u-py3.7\lib\site-packages\_pytest\config\__init__.py", line 1354, in parse
    self._preparse(args, addopts=addopts)
  File "C:\Users\kristjan\AppData\Local\pypoetry\Cache\virtualenvs\strawberry-graphql-TghffK6u-py3.7\lib\site-packages\_pytest\config\__init__.py", line 1257, in _preparse
    early_config=self, args=args, parser=self._parser
  File "C:\Users\kristjan\AppData\Local\pypoetry\Cache\virtualenvs\strawberry-graphql-TghffK6u-py3.7\lib\site-packages\pluggy\_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "C:\Users\kristjan\AppData\Local\pypoetry\Cache\virtualenvs\strawberry-graphql-TghffK6u-py3.7\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "C:\Users\kristjan\AppData\Local\pypoetry\Cache\virtualenvs\strawberry-graphql-TghffK6u-py3.7\lib\site-packages\pluggy\_callers.py", line 60, in _multicall
    return outcome.get_result()
  File "C:\Users\kristjan\AppData\Local\pypoetry\Cache\virtualenvs\strawberry-graphql-TghffK6u-py3.7\lib\site-packages\pluggy\_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "C:\Users\kristjan\AppData\Local\pypoetry\Cache\virtualenvs\strawberry-graphql-TghffK6u-py3.7\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "C:\Users\kristjan\AppData\Local\pypoetry\Cache\virtualenvs\strawberry-graphql-TghffK6u-py3.7\lib\site-packages\_pytest\config\__init__.py", line 1134, in pytest_load_initial_conftests
    early_config.known_args_namespace, rootpath=early_config.rootpath
  File "C:\Users\kristjan\AppData\Local\pypoetry\Cache\virtualenvs\strawberry-graphql-TghffK6u-py3.7\lib\site-packages\_pytest\config\__init__.py", line 556, in _set_initial_conftests
    self._try_load_conftest(anchor, namespace.importmode, rootpath)
  File "C:\Users\kristjan\AppData\Local\pypoetry\Cache\virtualenvs\strawberry-graphql-TghffK6u-py3.7\lib\site-packages\_pytest\config\__init__.py", line 578, in _try_load_conftest
    self._getconftestmodules(x, importmode, rootpath)
  File "C:\Users\kristjan\AppData\Local\pypoetry\Cache\virtualenvs\strawberry-graphql-TghffK6u-py3.7\lib\site-packages\_pytest\config\__init__.py", line 602, in _getconftestmodules
    mod = self._importconftest(conftestpath, importmode, rootpath)
  File "C:\Users\kristjan\AppData\Local\pypoetry\Cache\virtualenvs\strawberry-graphql-TghffK6u-py3.7\lib\site-packages\_pytest\config\__init__.py", line 647, in _importconftest
    assert mod not in mods, f"{mod} seem to be  loaded twice."
AssertionError: <module 'tests.conftest' from 'E:\\git\\strawberry\\tests\\conftest.py'> seem to be  loaded twice.

kristjanvalur avatar May 30 '23 16:05 kristjanvalur

You can at least change assert mod not in mods to assert mod not in mods, f"{mod} seem to be loaded twice.".

For me it simply reports that the conftest.py in my project root is loaded twice. I'm on Ubuntu 22.04 LTS and python 3.10. pytest 7.0.1 works fine, but any version beyond that, including the latest 7.3.1, is completely broken.

See below, /srv/vidicenter is my project root:

AssertionError: <module 'vidicenter.conftest' from '/srv/vidicenter/../vidicenter/conftest.py'> seem to be  loaded twice.

jgb avatar May 31 '23 09:05 jgb

I guess now the question is where is it loaded the first time ? And which one if is "wrong" if any are wrong.

Carreau avatar May 31 '23 09:05 Carreau

I guess that if this is the only place where loading is happening, I can add a traceback for my case when it successfully loads it the first time.

kristjanvalur avatar May 31 '23 10:05 kristjanvalur

Yes, well, adding an assert here, where it is initalizing self._dirpath2confmods:

        for parent in reversed((directory, *directory.parents)):
            if self._is_in_confcutdir(parent):
                conftestpath = parent / "conftest.py"
                if conftestpath.is_file():
                    mod = self._importconftest(conftestpath, importmode, rootpath)
                    clist.append(mod)
                    if "'tests.conftest'" in str(mod):
                        assert False, (mod, conftestpath, rootpath)
File "C:\Users\kristjan\AppData\Local\pypoetry\Cache\virtualenvs\strawberry-graphql-TghffK6u-py3.7\lib\site-packages\_pytest\config\__init__.py", line 1141, in pytest_load_initial_conftests
    early_config.known_args_namespace, rootpath=early_config.rootpath
  File "C:\Users\kristjan\AppData\Local\pypoetry\Cache\virtualenvs\strawberry-graphql-TghffK6u-py3.7\lib\site-packages\_pytest\config\__init__.py", line 556, in _set_initial_conftests
    self._try_load_conftest(anchor, namespace.importmode, rootpath)
  File "C:\Users\kristjan\AppData\Local\pypoetry\Cache\virtualenvs\strawberry-graphql-TghffK6u-py3.7\lib\site-packages\_pytest\config\__init__.py", line 573, in _try_load_conftest
    self._getconftestmodules(anchor, importmode, rootpath)
  File "C:\Users\kristjan\AppData\Local\pypoetry\Cache\virtualenvs\strawberry-graphql-TghffK6u-py3.7\lib\site-packages\_pytest\config\__init__.py", line 605, in _getconftestmodules
    assert False, (mod, conftestpath, rootpath)
AssertionError: (<module 'tests.conftest' from 'E:\\git\\strawberry\\tests\\conftest.py'>, WindowsPath('e:/git/strawberry/tests/conftest.py'), WindowsPath('e:/git/strawberry'))

This is where it is added to the _dirpath2confmods thing first.

kristjanvalur avatar Jun 01 '23 17:06 kristjanvalur