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