Elffuss BraidHub

kikocis/auto-code-rover public

main · 15.3 KiBRawPermalink
1{
2 "task_id": "pytest-dev__pytest-8906",
3 "setup_info": {
4 "repo_path": "/media/media0/yuntong/SWE-bench/testbed/pytest-dev__pytest/setup_pytest-dev__pytest__7.0",
5 "env_name": "setup_pytest-dev__pytest__7.0",
6 "pre_install": [],
7 "install": "python -m pip install -e .",
8 "test_cmd": "pytest -rA testing/test_skipping.py"
9 },
10 "task_info": {
11 "instance_id": "pytest-dev__pytest-8906",
12 "base_commit": "69356d20cfee9a81972dcbf93d8caf9eabe113e8",
13 "hints_text": "SyntaxErrors are thrown before execution, so how would the skip call stop the interpreter from parsing the 'incorrect' syntax?\r\nunless we hook the interpreter that is.\r\nA solution could be to ignore syntax errors based on some parameter\r\nif needed we can extend this to have some functionality to evaluate conditions in which syntax errors should be ignored\r\nplease note what i suggest will not fix other compatibility issues, just syntax errors\r\n\n> SyntaxErrors are thrown before execution, so how would the skip call stop the interpreter from parsing the 'incorrect' syntax?\r\n\r\nThe Python 3.8 code is included by an import. the idea is that the import should not happen if we are skipping the module.\r\n```python\r\nif sys.version_info < (3, 8):\r\n skip(msg=\"Requires Python >= 3.8\", allow_module_level=True)\r\n\r\n# import must be after the module level skip:\r\nfrom pos_only import *\r\n```\nHi @omry,\r\n\r\nThanks for raising this.\r\n\r\nDefinitely we should improve that message. \r\n\r\n> Explain skip with allow_module_level in the error message. this seems in conflict with the spirit of the message.\r\n\r\nI'm \ud83d\udc4d on this. 2 is also good, but because `allow_module_level` already exists and is part of the public API, I don't think introducing a new API will really help, better to improve the docs of what we already have.\r\n\r\nPerhaps improve the message to something like this:\r\n\r\n```\r\nUsing pytest.skip outside of a test will skip the entire module, if that's your intention pass `allow_module_level=True`. \r\nIf you want to skip a specific test or entire class, use the @pytest.mark.skip or @pytest.mark.skipif decorators.\r\n```\r\n\r\nI think we can drop the `pytestmark` remark from there, it is not skip-specific and passing `allow_module_level` already accomplishes the same.\r\n\nThanks @nicoddemus.\r\n\r\n> Using pytest.skip outside of a test will skip the entire module, if that's your intention pass `allow_module_level=True`. \r\nIf you want to skip a specific test or entire class, use the @pytest.mark.skip or @pytest.mark.skipif decorators.\r\n\r\nThis sounds clearer.\r\nCan you give a bit of context of why the message is there in the first place?\r\nIt sounds like we should be able to automatically detect if this is skipping a test or skipping the entire module (based on the fact that we can issue the warning).\r\n\r\nMaybe this is addressing some past confusion, or we want to push people toward `pytest.mark.skip[if]`, but if we can detect it automatically - we can also deprecate allow_module_level and make `skip()` do the right thing based on the context it's used in.\n> Maybe this is addressing some past confusion\r\n\r\nThat's exactly it, people would use `@pytest.skip` instead of `@pytest.mark.skip` and skip the whole module:\r\n\r\nhttps://github.com/pytest-dev/pytest/issues/2338#issuecomment-290324255\r\n\r\nFor that reason we don't really want to automatically detect things, but want users to explicitly pass that flag which proves they are not doing it by accident.\r\n\r\nOriginal issue: https://github.com/pytest-dev/pytest/issues/607\nHaving looked at the links, I think the alternative API to skip a module is more appealing.\r\nHere is a proposed end state:\r\n\r\n1. pytest.skip_module is introduced, can be used to skip a module.\r\n2. pytest.skip() is only legal inside of a test. If called outside of a test, an error message is issues.\r\nExample:\r\n\r\n> pytest.skip should only be used inside tests. To skip a module use pytest.skip_module. To completely skip a test function or a test class, use the @pytest.mark.skip or @pytest.mark.skipif decorators.\r\n\r\nGetting to this end state would include deprecating allow_module_level first, directing people using pytest.skip(allow_module_level=True) to use pytest.skip_module().\r\n\r\nI am also fine with just changing the message as you initially proposed but I feel this proposal will result in an healthier state.\r\n\n-0.5 from my side - I think this is too minor to warrant another deprecation and change.\nI agree it would be healthier, but -1 from me for the same reasons as @The-Compiler: we already had a deprecation/change period in order to introduce `allow_module_level`, having yet another one is frustrating/confusing to users, in comparison to the small gains.\nHi, I see that this is still open. If available, I'd like to take this up.",
14 "created_at": "2021-07-14T08:00:50Z",
15 "test_patch": "diff --git a/testing/test_skipping.py b/testing/test_skipping.py\n--- a/testing/test_skipping.py\n+++ b/testing/test_skipping.py\n@@ -1341,7 +1341,7 @@ def test_func():\n )\n result = pytester.runpytest()\n result.stdout.fnmatch_lines(\n- [\"*Using pytest.skip outside of a test is not allowed*\"]\n+ [\"*Using pytest.skip outside of a test will skip the entire module*\"]\n )\n \n \n",
16 "repo": "pytest-dev/pytest",
17 "problem_statement": "Improve handling of skip for module level\nThis is potentially about updating docs, updating error messages or introducing a new API.\r\n\r\nConsider the following scenario:\r\n\r\n`pos_only.py` is using Python 3,8 syntax:\r\n```python\r\ndef foo(a, /, b):\r\n return a + b\r\n```\r\n\r\nIt should not be tested under Python 3.6 and 3.7.\r\nThis is a proper way to skip the test in Python older than 3.8:\r\n```python\r\nfrom pytest import raises, skip\r\nimport sys\r\nif sys.version_info < (3, 8):\r\n skip(msg=\"Requires Python >= 3.8\", allow_module_level=True)\r\n\r\n# import must be after the module level skip:\r\nfrom pos_only import *\r\n\r\ndef test_foo():\r\n assert foo(10, 20) == 30\r\n assert foo(10, b=20) == 30\r\n with raises(TypeError):\r\n assert foo(a=10, b=20)\r\n```\r\n\r\nMy actual test involves parameterize and a 3.8 only class, so skipping the test itself is not sufficient because the 3.8 class was used in the parameterization.\r\n\r\nA naive user will try to initially skip the module like:\r\n\r\n```python\r\nif sys.version_info < (3, 8):\r\n skip(msg=\"Requires Python >= 3.8\")\r\n```\r\nThis issues this error:\r\n\r\n>Using pytest.skip outside of a test is not allowed. To decorate a test function, use the @pytest.mark.skip or @pytest.mark.skipif decorators instead, and to skip a module use `pytestmark = pytest.mark.{skip,skipif}.\r\n\r\nThe proposed solution `pytestmark = pytest.mark.{skip,skipif}`, does not work in my case: pytest continues to process the file and fail when it hits the 3.8 syntax (when running with an older version of Python).\r\n\r\nThe correct solution, to use skip as a function is actively discouraged by the error message.\r\n\r\nThis area feels a bit unpolished.\r\nA few ideas to improve:\r\n\r\n1. Explain skip with `allow_module_level` in the error message. this seems in conflict with the spirit of the message.\r\n2. Create an alternative API to skip a module to make things easier: `skip_module(\"reason\")`, which can call `_skip(msg=msg, allow_module_level=True)`.\r\n\r\n\n",
18 "version": "7.0",
19 "FAIL_TO_PASS": [
20 "testing/test_skipping.py::test_module_level_skip_error"
21 ],
22 "PASS_TO_PASS": [
23 "testing/test_skipping.py::TestBooleanCondition::test_skipif",
24 "testing/test_skipping.py::TestBooleanCondition::test_skipif_noreason",
25 "testing/test_skipping.py::TestBooleanCondition::test_xfail",
26 "testing/test_skipping.py::TestEvaluation::test_marked_one_arg",
27 "testing/test_skipping.py::TestEvaluation::test_marked_one_arg_twice",
28 "testing/test_skipping.py::TestEvaluation::test_marked_one_arg_twice2",
29 "testing/test_skipping.py::TestEvaluation::test_marked_one_arg_with_reason",
30 "testing/test_skipping.py::TestEvaluation::test_marked_skipif_no_args",
31 "testing/test_skipping.py::TestEvaluation::test_marked_skipif_with_boolean_without_reason",
32 "testing/test_skipping.py::TestEvaluation::test_marked_skipif_with_invalid_boolean",
33 "testing/test_skipping.py::TestEvaluation::test_marked_xfail_no_args",
34 "testing/test_skipping.py::TestEvaluation::test_no_marker",
35 "testing/test_skipping.py::TestEvaluation::test_skipif_class",
36 "testing/test_skipping.py::TestEvaluation::test_skipif_markeval_namespace",
37 "testing/test_skipping.py::TestEvaluation::test_skipif_markeval_namespace_ValueError",
38 "testing/test_skipping.py::TestEvaluation::test_skipif_markeval_namespace_multiple",
39 "testing/test_skipping.py::TestSkip::test_arg_as_reason",
40 "testing/test_skipping.py::TestSkip::test_only_skips_marked_test",
41 "testing/test_skipping.py::TestSkip::test_skip_class",
42 "testing/test_skipping.py::TestSkip::test_skip_no_reason",
43 "testing/test_skipping.py::TestSkip::test_skip_with_reason",
44 "testing/test_skipping.py::TestSkip::test_skips_on_false_string",
45 "testing/test_skipping.py::TestSkip::test_strict_and_skip",
46 "testing/test_skipping.py::TestSkip::test_wrong_skip_usage",
47 "testing/test_skipping.py::TestSkipif::test_skipif_conditional",
48 "testing/test_skipping.py::TestSkipif::test_skipif_reporting[\"hasattr(sys,",
49 "testing/test_skipping.py::TestSkipif::test_skipif_reporting[True,",
50 "testing/test_skipping.py::TestSkipif::test_skipif_reporting_multiple[skipif-SKIP-skipped]",
51 "testing/test_skipping.py::TestSkipif::test_skipif_reporting_multiple[xfail-XPASS-xpassed]",
52 "testing/test_skipping.py::TestSkipif::test_skipif_using_platform",
53 "testing/test_skipping.py::TestXFail::test_dynamic_xfail_no_run",
54 "testing/test_skipping.py::TestXFail::test_dynamic_xfail_set_during_funcarg_setup",
55 "testing/test_skipping.py::TestXFail::test_dynamic_xfail_set_during_runtest_failed",
56 "testing/test_skipping.py::TestXFail::test_dynamic_xfail_set_during_runtest_passed_strict",
57 "testing/test_skipping.py::TestXFail::test_strict_sanity",
58 "testing/test_skipping.py::TestXFail::test_strict_xfail[False]",
59 "testing/test_skipping.py::TestXFail::test_strict_xfail[True]",
60 "testing/test_skipping.py::TestXFail::test_strict_xfail_condition[False]",
61 "testing/test_skipping.py::TestXFail::test_strict_xfail_condition[True]",
62 "testing/test_skipping.py::TestXFail::test_strict_xfail_default_from_file[false]",
63 "testing/test_skipping.py::TestXFail::test_strict_xfail_default_from_file[true]",
64 "testing/test_skipping.py::TestXFail::test_xfail_condition_keyword[False]",
65 "testing/test_skipping.py::TestXFail::test_xfail_condition_keyword[True]",
66 "testing/test_skipping.py::TestXFail::test_xfail_evalfalse_but_fails",
67 "testing/test_skipping.py::TestXFail::test_xfail_imperative",
68 "testing/test_skipping.py::TestXFail::test_xfail_imperative_in_setup_function",
69 "testing/test_skipping.py::TestXFail::test_xfail_markeval_namespace",
70 "testing/test_skipping.py::TestXFail::test_xfail_not_report_default",
71 "testing/test_skipping.py::TestXFail::test_xfail_not_run_no_setup_run",
72 "testing/test_skipping.py::TestXFail::test_xfail_not_run_xfail_reporting",
73 "testing/test_skipping.py::TestXFail::test_xfail_raises[(AttributeError,",
74 "testing/test_skipping.py::TestXFail::test_xfail_raises[TypeError-IndexError-*1",
75 "testing/test_skipping.py::TestXFail::test_xfail_raises[TypeError-TypeError-*1",
76 "testing/test_skipping.py::TestXFail::test_xfail_run_anyway",
77 "testing/test_skipping.py::TestXFail::test_xfail_run_with_skip_mark[test_input0-expected0]",
78 "testing/test_skipping.py::TestXFail::test_xfail_run_with_skip_mark[test_input1-expected1]",
79 "testing/test_skipping.py::TestXFail::test_xfail_simple[False]",
80 "testing/test_skipping.py::TestXFail::test_xfail_simple[True]",
81 "testing/test_skipping.py::TestXFail::test_xfail_using_platform",
82 "testing/test_skipping.py::TestXFail::test_xfail_xpass",
83 "testing/test_skipping.py::TestXFail::test_xfail_xpassed",
84 "testing/test_skipping.py::TestXFail::test_xfail_xpassed_strict",
85 "testing/test_skipping.py::TestXFailwithSetupTeardown::test_failing_setup_issue9",
86 "testing/test_skipping.py::TestXFailwithSetupTeardown::test_failing_teardown_issue9",
87 "testing/test_skipping.py::test_default_markers",
88 "testing/test_skipping.py::test_errors_in_xfail_skip_expressions",
89 "testing/test_skipping.py::test_imperativeskip_on_xfail_test",
90 "testing/test_skipping.py::test_importorskip",
91 "testing/test_skipping.py::test_invalid_skip_keyword_parameter",
92 "testing/test_skipping.py::test_mark_xfail_item",
93 "testing/test_skipping.py::test_module_level_skip_with_allow_module_level",
94 "testing/test_skipping.py::test_relpath_rootdir",
95 "testing/test_skipping.py::test_reportchars",
96 "testing/test_skipping.py::test_reportchars_all",
97 "testing/test_skipping.py::test_reportchars_all_error",
98 "testing/test_skipping.py::test_reportchars_error",
99 "testing/test_skipping.py::test_skip_not_report_default",
100 "testing/test_skipping.py::test_skipif_class",
101 "testing/test_skipping.py::test_skipped_folding",
102 "testing/test_skipping.py::test_skipped_reasons_functional",
103 "testing/test_skipping.py::test_summary_list_after_errors",
104 "testing/test_skipping.py::test_xfail_item",
105 "testing/test_skipping.py::test_xfail_skipif_with_globals",
106 "testing/test_skipping.py::test_xfail_test_setup_exception"
107 ],
108 "environment_setup_commit": "e2ee3144ed6e241dea8d96215fcdca18b3892551",
109 "patch": "diff --git a/src/_pytest/python.py b/src/_pytest/python.py\n--- a/src/_pytest/python.py\n+++ b/src/_pytest/python.py\n@@ -608,10 +608,10 @@ def _importtestmodule(self):\n if e.allow_module_level:\n raise\n raise self.CollectError(\n- \"Using pytest.skip outside of a test is not allowed. \"\n- \"To decorate a test function, use the @pytest.mark.skip \"\n- \"or @pytest.mark.skipif decorators instead, and to skip a \"\n- \"module use `pytestmark = pytest.mark.{skip,skipif}.\"\n+ \"Using pytest.skip outside of a test will skip the entire module. \"\n+ \"If that's your intention, pass `allow_module_level=True`. \"\n+ \"If you want to skip a specific test or an entire class, \"\n+ \"use the @pytest.mark.skip or @pytest.mark.skipif decorators.\"\n ) from e\n self.config.pluginmanager.consider_module(mod)\n return mod\n",
110 "pr_link": "https://github.com/pytest-dev/pytest/pull/8906"
111 }
112}