Elffuss BraidHub

kikocis/auto-code-rover public

main · 1.0 KiBRawPermalink
1Incorrect caching of skipif/xfail string condition evaluation
2Version: pytest 5.4.3, current master
3
4pytest 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:
5
6```py
7# test_module_1.py
8import pytest
9
10skip = True
11
12@pytest.mark.skipif("skip")
13def test_should_skip():
14 assert False
15```
16
17```py
18# test_module_2.py
19import pytest
20
21skip = False
22
23@pytest.mark.skipif("skip")
24def test_should_not_skip():
25 assert False
26```
27
28Running `pytest test_module_1.py test_module_2.py`.
29
30Expected: `test_should_skip` is skipped, `test_should_not_skip` is not skipped.
31
32Actual: both are skipped.
33
34---
35
36I 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`.