Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

documentation recommends accessing config.cache in an unsafe way #14148

Copy link
Copy link

Description

@DetachHead
Issue body actions

https://docs.pytest.org/en/stable/how-to/cache.html#the-new-config-cache-object

in this example recommends accessing pytestconfig.cache which will crash at runtime if the cacheprovider plugin has been disabled as mentioned here:

_______________________________________________________________________________ ERROR at setup of test_function ________________________________________________________________________________

pytestconfig = <_pytest.config.Config object at 0x749189eaa7b0>

    @pytest.fixture
    def mydata(pytestconfig):
>       val = pytestconfig.cache.get("example/value", None)
E       AttributeError: 'Config' object has no attribute 'cache'

python/tests/test_asdf.py:12: AttributeError
=================================================================================== short test summary info ====================================================================================
ERROR python/tests/test_asdf.py::test_function - AttributeError: 'Config' object has no attribute 'cache'
======================================================================================= 1 error in 0.07s =======================================================================================

pytest should set the cache object to None when the plugin isn't enabled. that way, type checkers will report an error when attempting to use it without checking whether it's None

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.