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

AttributeError: 'Config' object has no attribute 'cache' with cacheprovider disabled #408

Closed
mandeepsandhu opened this issue Nov 10, 2021 · 4 comments · Fixed by #409
Closed

Comments

@mandeepsandhu
Copy link

Python Version

3.8.10

pytest Version

6.2.5

Package Version

3.10.1

Description

pytest fails to run tests if cacheprovider plugin is disabled during test execution.

Steps to reproduce error

  1. Sample test:
$ cat test_pass.py
def test_pass1():
    assert True

def test_pass2():
    assert True
  1. Run test with pytest caching disabled:
$ pytest -p no:cacheprovider test_pass.py -v
================================================================================= test session starts =================================================================================
platform linux -- Python 3.8.10, pytest-6.2.5, py-1.10.0, pluggy-0.13.1 -- /usr/bin/python3
rootdir: /tmp/pytest-of-mandeepsandhu/mytest
collected 2 items                                                                                                                                                                     

test_pass.py::test_pass1 PASSED                                                                                                                                                 [ 50%]
test_pass.py::test_pass2 PASSED                                                                                                                                                 [100%]

================================================================================== 2 passed in 0.00s ==================================================================================

  1. Install pytest-randomly and repeat step 2
$ pip install --user pytest-randomly
...
Successfully installed pytest-randomly-3.10.1
$ pytest -p no:cacheprovider test_pass.py -v
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/home/mandeepsandhu/.local/lib/python3.8/site-packages/_pytest/main.py", line 265, in wrap_session
INTERNALERROR>     config._do_configure()
INTERNALERROR>   File "/home/mandeepsandhu/.local/lib/python3.8/site-packages/_pytest/config/__init__.py", line 982, in _do_configure
INTERNALERROR>     self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR>   File "/home/mandeepsandhu/.local/lib/python3.8/site-packages/pluggy/hooks.py", line 308, in call_historic
INTERNALERROR>     res = self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/home/mandeepsandhu/.local/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/home/mandeepsandhu/.local/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda>
INTERNALERROR>     self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR>   File "/home/mandeepsandhu/.local/lib/python3.8/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/home/mandeepsandhu/.local/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/home/mandeepsandhu/.local/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/mandeepsandhu/.local/lib/python3.8/site-packages/pytest_randomly/__init__.py", line 116, in pytest_configure
INTERNALERROR>     assert config.cache is not None
INTERNALERROR> AttributeError: 'Config' object has no attribute 'cache'
  1. Running with randomly disabled, works:
$ pytest -p no:cacheprovider -p no:randomly test_pass.py -v
================================================================================= test session starts =================================================================================
platform linux -- Python 3.8.10, pytest-6.2.5, py-1.10.0, pluggy-0.13.1 -- /usr/bin/python3
rootdir: /tmp/pytest-of-mandeepsandhu/mytest
collected 2 items                                                                                                                                                                     

test_pass.py::test_pass1 PASSED                                                                                                                                                 [ 50%]
test_pass.py::test_pass2 PASSED                                                                                                                                                 [100%]

================================================================================== 2 passed in 0.00s ==================================================================================

@adamchainz
Copy link
Member

Yeah we could rework to not need the cache.

@mandeepsandhu
Copy link
Author

Thanks. In my case I have caching disabled since my tests run inside a read-only container filesystem (run by AWS lambda), although having the tests execute randomly is still desirable.

@adamchainz
Copy link
Member

Thanks for describing your use case.

Fix released in 3.10.2, try that.

@mandeepsandhu
Copy link
Author

Thanks for describing your use case.

Fix released in 3.10.2, try that.

I can confirm the fix in 3.10.2:

$ pytest -p no:cacheprovider test_pass.py -v
================================================================================= test session starts =================================================================================
platform linux -- Python 3.8.10, pytest-6.2.5, py-1.10.0, pluggy-0.13.1 -- /usr/bin/python3
Using --randomly-seed=3228386608
rootdir: /tmp/mytest
plugins: randomly-3.10.2
collected 2 items                                                                                                                                                                     

test_pass.py::test_pass1 PASSED                                                                                                                                                 [ 50%]
test_pass.py::test_pass2 PASSED                                                                                                                                                 [100%]

================================================================================== 2 passed in 0.01s ==================================================================================

Thanks for the quick fix @adamchainz 🙏

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