-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Labels
good first issueeasy issue that is friendly to new contributoreasy issue that is friendly to new contributortopic: marksrelated to marks, either the general marks or builtinrelated to marks, either the general marks or builtintype: bugproblem that needs to be addressedproblem that needs to be addressed
Description
Version: pytest 5.4.3, current master
pytest caches the evaluation of the string in e.g. @pytest.mark.skipif("sys.platform == 'win32'")
. The caching key is only the string itself (see cached_eval
in _pytest/mark/evaluate.py
). However, the evaluation also depends on the item's globals, so the caching can lead to incorrect results. Example:
# test_module_1.py
import pytest
skip = True
@pytest.mark.skipif("skip")
def test_should_skip():
assert False
# test_module_2.py
import pytest
skip = False
@pytest.mark.skipif("skip")
def test_should_not_skip():
assert False
Running pytest test_module_1.py test_module_2.py
.
Expected: test_should_skip
is skipped, test_should_not_skip
is not skipped.
Actual: both are skipped.
I think the most appropriate fix is to simply remove the caching, which I don't think is necessary really, and inline cached_eval
into MarkEvaluator._istrue
.
andrew222651
Metadata
Metadata
Assignees
Labels
good first issueeasy issue that is friendly to new contributoreasy issue that is friendly to new contributortopic: marksrelated to marks, either the general marks or builtinrelated to marks, either the general marks or builtintype: bugproblem that needs to be addressedproblem that needs to be addressed