| 1 | { |
| 2 | "task_id": "pytest-dev__pytest-7373", |
| 3 | "setup_info": { |
| 4 | "repo_path": "/media/media0/yuntong/SWE-bench/testbed/pytest-dev__pytest/setup_pytest-dev__pytest__5.4", |
| 5 | "env_name": "setup_pytest-dev__pytest__5.4", |
| 6 | "pre_install": [], |
| 7 | "install": "python -m pip install -e .", |
| 8 | "test_cmd": "pytest -rA testing/test_mark.py" |
| 9 | }, |
| 10 | "task_info": { |
| 11 | "instance_id": "pytest-dev__pytest-7373", |
| 12 | "base_commit": "7b77fc086aab8b3a8ebc890200371884555eea1e", |
| 13 | "hints_text": "> 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.\r\n\r\nI agree:\r\n\r\n* While it might have some performance impact with very large test suites which use marks with eval, the simple workaround is to not use the eval feature on those, which is more predictable anyway.\r\n* I don't see a clean way to turn \"globals\" in some kind of cache key without having some performance impact and/or adverse effects.\r\n\r\nSo \ud83d\udc4d from me to simply removing this caching. \nAs globals are dynamic, i would propose to drop the cache as well, we should investigate reinstating a cache later on ", |
| 14 | "created_at": "2020-06-15T17:12:08Z", |
| 15 | "test_patch": "diff --git a/testing/test_mark.py b/testing/test_mark.py\n--- a/testing/test_mark.py\n+++ b/testing/test_mark.py\n@@ -706,6 +706,36 @@ def test_1(parameter):\n reprec = testdir.inline_run()\n reprec.assertoutcome(skipped=1)\n \n+ def test_reevaluate_dynamic_expr(self, testdir):\n+ \"\"\"#7360\"\"\"\n+ py_file1 = testdir.makepyfile(\n+ test_reevaluate_dynamic_expr1=\"\"\"\n+ import pytest\n+\n+ skip = True\n+\n+ @pytest.mark.skipif(\"skip\")\n+ def test_should_skip():\n+ assert True\n+ \"\"\"\n+ )\n+ py_file2 = testdir.makepyfile(\n+ test_reevaluate_dynamic_expr2=\"\"\"\n+ import pytest\n+\n+ skip = False\n+\n+ @pytest.mark.skipif(\"skip\")\n+ def test_should_not_skip():\n+ assert True\n+ \"\"\"\n+ )\n+\n+ file_name1 = os.path.basename(py_file1.strpath)\n+ file_name2 = os.path.basename(py_file2.strpath)\n+ reprec = testdir.inline_run(file_name1, file_name2)\n+ reprec.assertoutcome(passed=1, skipped=1)\n+\n \n class TestKeywordSelection:\n def test_select_simple(self, testdir):\n", |
| 16 | "repo": "pytest-dev/pytest", |
| 17 | "problem_statement": "Incorrect caching of skipif/xfail string condition evaluation\nVersion: pytest 5.4.3, current master\r\n\r\npytest 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:\r\n\r\n```py\r\n# test_module_1.py\r\nimport pytest\r\n\r\nskip = True\r\n\r\n@pytest.mark.skipif(\"skip\")\r\ndef test_should_skip():\r\n assert False\r\n```\r\n\r\n```py\r\n# test_module_2.py\r\nimport pytest\r\n\r\nskip = False\r\n\r\n@pytest.mark.skipif(\"skip\")\r\ndef test_should_not_skip():\r\n assert False\r\n```\r\n\r\nRunning `pytest test_module_1.py test_module_2.py`.\r\n\r\nExpected: `test_should_skip` is skipped, `test_should_not_skip` is not skipped.\r\n\r\nActual: both are skipped.\r\n\r\n---\r\n\r\nI 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`.\n", |
| 18 | "version": "5.4", |
| 19 | "FAIL_TO_PASS": [ |
| 20 | "testing/test_mark.py::TestFunctional::test_reevaluate_dynamic_expr" |
| 21 | ], |
| 22 | "PASS_TO_PASS": [ |
| 23 | "testing/test_mark.py::TestFunctional::test_keyword_added_for_session", |
| 24 | "testing/test_mark.py::TestFunctional::test_keywords_at_node_level", |
| 25 | "testing/test_mark.py::TestFunctional::test_mark_closest", |
| 26 | "testing/test_mark.py::TestFunctional::test_mark_decorator_baseclasses_merged", |
| 27 | "testing/test_mark.py::TestFunctional::test_mark_decorator_subclass_does_not_propagate_to_base", |
| 28 | "testing/test_mark.py::TestFunctional::test_mark_dynamically_in_funcarg", |
| 29 | "testing/test_mark.py::TestFunctional::test_mark_from_parameters", |
| 30 | "testing/test_mark.py::TestFunctional::test_mark_should_not_pass_to_siebling_class", |
| 31 | "testing/test_mark.py::TestFunctional::test_mark_with_wrong_marker", |
| 32 | "testing/test_mark.py::TestFunctional::test_merging_markers_deep", |
| 33 | "testing/test_mark.py::TestFunctional::test_no_marker_match_on_unmarked_names", |
| 34 | "testing/test_mark.py::TestKeywordSelection::test_keyword_extra", |
| 35 | "testing/test_mark.py::TestKeywordSelection::test_no_magic_values[+]", |
| 36 | "testing/test_mark.py::TestKeywordSelection::test_no_magic_values[..]", |
| 37 | "testing/test_mark.py::TestKeywordSelection::test_no_magic_values[__]", |
| 38 | "testing/test_mark.py::TestKeywordSelection::test_no_match_directories_outside_the_suite", |
| 39 | "testing/test_mark.py::TestKeywordSelection::test_select_extra_keywords[TestClass", |
| 40 | "testing/test_mark.py::TestKeywordSelection::test_select_extra_keywords[TestClass]", |
| 41 | "testing/test_mark.py::TestKeywordSelection::test_select_extra_keywords[xxx", |
| 42 | "testing/test_mark.py::TestKeywordSelection::test_select_extra_keywords[xxx]", |
| 43 | "testing/test_mark.py::TestKeywordSelection::test_select_simple", |
| 44 | "testing/test_mark.py::TestKeywordSelection::test_select_starton", |
| 45 | "testing/test_mark.py::TestMark::test_mark_with_param", |
| 46 | "testing/test_mark.py::TestMark::test_pytest_exists_in_namespace_all[py.test-mark]", |
| 47 | "testing/test_mark.py::TestMark::test_pytest_exists_in_namespace_all[py.test-param]", |
| 48 | "testing/test_mark.py::TestMark::test_pytest_exists_in_namespace_all[pytest-mark]", |
| 49 | "testing/test_mark.py::TestMark::test_pytest_exists_in_namespace_all[pytest-param]", |
| 50 | "testing/test_mark.py::TestMark::test_pytest_mark_name_starts_with_underscore", |
| 51 | "testing/test_mark.py::TestMark::test_pytest_mark_notcallable", |
| 52 | "testing/test_mark.py::TestMarkDecorator::test__eq__[foo-rhs3-False]", |
| 53 | "testing/test_mark.py::TestMarkDecorator::test__eq__[lhs0-rhs0-True]", |
| 54 | "testing/test_mark.py::TestMarkDecorator::test__eq__[lhs1-rhs1-False]", |
| 55 | "testing/test_mark.py::TestMarkDecorator::test__eq__[lhs2-bar-False]", |
| 56 | "testing/test_mark.py::TestMarkDecorator::test_aliases", |
| 57 | "testing/test_mark.py::test_addmarker_order", |
| 58 | "testing/test_mark.py::test_ini_markers", |
| 59 | "testing/test_mark.py::test_ini_markers_whitespace", |
| 60 | "testing/test_mark.py::test_keyword_option_considers_mark", |
| 61 | "testing/test_mark.py::test_keyword_option_custom[1", |
| 62 | "testing/test_mark.py::test_keyword_option_custom[interface-expected_passed0]", |
| 63 | "testing/test_mark.py::test_keyword_option_custom[not", |
| 64 | "testing/test_mark.py::test_keyword_option_custom[pass-expected_passed2]", |
| 65 | "testing/test_mark.py::test_keyword_option_parametrize[2-3-expected_passed2]", |
| 66 | "testing/test_mark.py::test_keyword_option_parametrize[None-expected_passed0]", |
| 67 | "testing/test_mark.py::test_keyword_option_parametrize[[1.3]-expected_passed1]", |
| 68 | "testing/test_mark.py::test_keyword_option_wrong_arguments[(foo-at", |
| 69 | "testing/test_mark.py::test_keyword_option_wrong_arguments[foo", |
| 70 | "testing/test_mark.py::test_keyword_option_wrong_arguments[not", |
| 71 | "testing/test_mark.py::test_keyword_option_wrong_arguments[or", |
| 72 | "testing/test_mark.py::test_mark_expressions_no_smear", |
| 73 | "testing/test_mark.py::test_mark_on_pseudo_function", |
| 74 | "testing/test_mark.py::test_mark_option[(((", |
| 75 | "testing/test_mark.py::test_mark_option[not", |
| 76 | "testing/test_mark.py::test_mark_option[xyz", |
| 77 | "testing/test_mark.py::test_mark_option[xyz-expected_passed0]", |
| 78 | "testing/test_mark.py::test_mark_option[xyz2-expected_passed4]", |
| 79 | "testing/test_mark.py::test_mark_option_custom[interface-expected_passed0]", |
| 80 | "testing/test_mark.py::test_mark_option_custom[not", |
| 81 | "testing/test_mark.py::test_marked_class_run_twice", |
| 82 | "testing/test_mark.py::test_marker_expr_eval_failure_handling[NOT", |
| 83 | "testing/test_mark.py::test_marker_expr_eval_failure_handling[bogus/]", |
| 84 | "testing/test_mark.py::test_marker_without_description", |
| 85 | "testing/test_mark.py::test_markers_from_parametrize", |
| 86 | "testing/test_mark.py::test_markers_option", |
| 87 | "testing/test_mark.py::test_markers_option_with_plugin_in_current_dir", |
| 88 | "testing/test_mark.py::test_parameterset_for_fail_at_collect", |
| 89 | "testing/test_mark.py::test_parameterset_for_parametrize_bad_markname", |
| 90 | "testing/test_mark.py::test_parameterset_for_parametrize_marks[None]", |
| 91 | "testing/test_mark.py::test_parameterset_for_parametrize_marks[]", |
| 92 | "testing/test_mark.py::test_parameterset_for_parametrize_marks[skip]", |
| 93 | "testing/test_mark.py::test_parameterset_for_parametrize_marks[xfail]", |
| 94 | "testing/test_mark.py::test_parametrize_iterator", |
| 95 | "testing/test_mark.py::test_parametrize_with_module", |
| 96 | "testing/test_mark.py::test_parametrized_collect_with_wrong_args", |
| 97 | "testing/test_mark.py::test_parametrized_collected_from_command_line", |
| 98 | "testing/test_mark.py::test_parametrized_with_kwargs", |
| 99 | "testing/test_mark.py::test_pytest_param_id_allows_none_or_string[None]", |
| 100 | "testing/test_mark.py::test_pytest_param_id_allows_none_or_string[hello", |
| 101 | "testing/test_mark.py::test_pytest_param_id_requires_string", |
| 102 | "testing/test_mark.py::test_strict_prohibits_unregistered_markers[--strict-markers]", |
| 103 | "testing/test_mark.py::test_strict_prohibits_unregistered_markers[--strict]" |
| 104 | ], |
| 105 | "environment_setup_commit": "678c1a0745f1cf175c442c719906a1f13e496910", |
| 106 | "patch": "diff --git a/src/_pytest/mark/evaluate.py b/src/_pytest/mark/evaluate.py\n--- a/src/_pytest/mark/evaluate.py\n+++ b/src/_pytest/mark/evaluate.py\n@@ -10,25 +10,14 @@\n from ..outcomes import fail\n from ..outcomes import TEST_OUTCOME\n from .structures import Mark\n-from _pytest.config import Config\n from _pytest.nodes import Item\n-from _pytest.store import StoreKey\n \n \n-evalcache_key = StoreKey[Dict[str, Any]]()\n+def compiled_eval(expr: str, d: Dict[str, object]) -> Any:\n+ import _pytest._code\n \n-\n-def cached_eval(config: Config, expr: str, d: Dict[str, object]) -> Any:\n- default = {} # type: Dict[str, object]\n- evalcache = config._store.setdefault(evalcache_key, default)\n- try:\n- return evalcache[expr]\n- except KeyError:\n- import _pytest._code\n-\n- exprcode = _pytest._code.compile(expr, mode=\"eval\")\n- evalcache[expr] = x = eval(exprcode, d)\n- return x\n+ exprcode = _pytest._code.compile(expr, mode=\"eval\")\n+ return eval(exprcode, d)\n \n \n class MarkEvaluator:\n@@ -98,7 +87,7 @@ def _istrue(self) -> bool:\n self.expr = expr\n if isinstance(expr, str):\n d = self._getglobals()\n- result = cached_eval(self.item.config, expr, d)\n+ result = compiled_eval(expr, d)\n else:\n if \"reason\" not in mark.kwargs:\n # XXX better be checked at collection time\n", |
| 107 | "pr_link": "https://github.com/pytest-dev/pytest/pull/7373" |
| 108 | } |
| 109 | } |