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 7.0: AttributeError: 'dict' object has no attribute 'config' #122

Closed
hugovk opened this issue Dec 8, 2021 · 3 comments
Closed

pytest 7.0: AttributeError: 'dict' object has no attribute 'config' #122

hugovk opened this issue Dec 8, 2021 · 3 comments

Comments

@hugovk
Copy link

hugovk commented Dec 8, 2021

pytest 7.0 RC1 is out, install with python3 -m pip install pytest==7.0.0rc1 or python3 -m pip install -U --pre pytest

$ python --version
Python 3.10.1
$ python3 -m pip freeze | grep pytest
pytest==7.0.0rc1
pytest-cov==3.0.0
pytest-forked==1.3.0
pytest-freezegun==0.4.2
pytest-timeout==2.0.1
pytest-watch==4.2.0
pytest-xdist==2.4.0
$ ptw test_it.py
Error: Could not run --collect-only to handle the pytest config file. Trying again without silencing output...
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/bin/ptw", line 8, in <module>
    sys.exit(main())
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pytest_watch/command.py", line 83, in main
    if not merge_config(args, pytest_args, verbose=args['--verbose']):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pytest_watch/config.py", line 87, in merge_config
    config_path = _collect_config(pytest_args, silent)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pytest_watch/config.py", line 79, in _collect_config
    return _run_pytest_collect(pytest_args)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pytest_watch/config.py", line 52, in _run_pytest_collect
    exit_code = pytest.main(argv, plugins=[collect_config_plugin])
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/_pytest/config/__init__.py", line 165, in main
    ret: Union[ExitCode, int] = config.hook.pytest_cmdline_main(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
    return outcome.get_result()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pytest_watch/config.py", line 41, in pytest_cmdline_main
    inifile = config.inicfg.config.path
AttributeError: 'dict' object has no attribute 'config'

pytest 6 works:

$ ptw test_it.py

[Wed Dec  8 09:49:24 2021] Running: /Library/Frameworks/Python.framework/Versions/3.10/bin/python3 -m pytest test_it.py
============================================= test session starts ==============================================
platform darwin -- Python 3.10.1, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: /Users/hugo/github/test
plugins: respx-0.19.0, freezegun-0.4.2, hypothesis-6.28.0, flaky-3.7.0, xdist-2.4.0, timeout-2.0.1, anyio-3.3.4, forked-1.3.0, cov-3.0.0
collected 1 item

test_it.py .                                                                                             [100%]

============================================== 1 passed in 0.04s ===============================================
@hugovk
Copy link
Author

hugovk commented Dec 8, 2021

It's hitting the # pytest < 2.7.0 branch here:

def pytest_cmdline_main(self, config):
if hasattr(config, 'inifile'):
# pytest >= 2.7.0
inifile = config.inifile
else:
# pytest < 2.7.0
inifile = config.inicfg.config.path
if inifile:
self.path = str(inifile)
raise StopCollect()

@The-Compiler
Copy link

Hm, we try to add the (deprecated) config.inifile, but we do so after pytest_cmdline_main, so it's not actually available there. I opened pytest-dev/pytest#9396 to track this.

You can/should fix this in pytest_watch too, though, by checking whether the new config.inipath is available first (which is a pathlib.Path rather than a py.path.local, but since you only seem to call str(...) on it, it will work the same way).

@hugovk hugovk mentioned this issue Dec 8, 2021
@hugovk
Copy link
Author

hugovk commented Dec 8, 2021

Thanks, here's a PR: #123

@hugovk hugovk closed this as not planned Won't fix, can't repro, duplicate, stale Sep 15, 2023
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

Successfully merging a pull request may close this issue.

2 participants