Elffuss BraidHub

kikocis/auto-code-rover public

main · 9.8 KiBRawPermalink
1{
2 "task_id": "pytest-dev__pytest-9359",
3 "setup_info": {
4 "repo_path": "/home/haifeng/projects/reverse-prompt/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/code/test_source.py"
9 },
10 "task_info": {
11 "instance_id": "pytest-dev__pytest-9359",
12 "base_commit": "e2ee3144ed6e241dea8d96215fcdca18b3892551",
13 "hints_text": "",
14 "created_at": "2021-12-01T14:31:38Z",
15 "test_patch": "diff --git a/testing/code/test_source.py b/testing/code/test_source.py\n--- a/testing/code/test_source.py\n+++ b/testing/code/test_source.py\n@@ -618,6 +618,19 @@ def something():\n assert str(source) == \"def func(): raise ValueError(42)\"\n \n \n+def test_decorator() -> None:\n+ s = \"\"\"\\\n+def foo(f):\n+ pass\n+\n+@foo\n+def bar():\n+ pass\n+ \"\"\"\n+ source = getstatement(3, s)\n+ assert \"@foo\" in str(source)\n+\n+\n def XXX_test_expression_multiline() -> None:\n source = \"\"\"\\\n something\n",
16 "repo": "pytest-dev/pytest",
17 "problem_statement": "Error message prints extra code line when using assert in python3.9\n<!--\r\nThanks for submitting an issue!\r\n\r\nQuick check-list while reporting bugs:\r\n-->\r\n\r\n- [x] a detailed description of the bug or problem you are having\r\n- [x] output of `pip list` from the virtual environment you are using\r\n- [x] pytest and operating system versions\r\n- [ ] minimal example if possible\r\n### Description\r\nI have a test like this:\r\n```\r\nfrom pytest import fixture\r\n\r\n\r\ndef t(foo):\r\n return foo\r\n\r\n\r\n@fixture\r\ndef foo():\r\n return 1\r\n\r\n\r\ndef test_right_statement(foo):\r\n assert foo == (3 + 2) * (6 + 9)\r\n\r\n @t\r\n def inner():\r\n return 2\r\n\r\n assert 2 == inner\r\n\r\n\r\n@t\r\ndef outer():\r\n return 2\r\n```\r\nThe test \"test_right_statement\" fails at the first assertion,but print extra code (the \"t\" decorator) in error details, like this:\r\n\r\n```\r\n ============================= test session starts =============================\r\nplatform win32 -- Python 3.9.6, pytest-6.2.5, py-1.10.0, pluggy-0.13.1 -- \r\ncachedir: .pytest_cache\r\nrootdir: \r\nplugins: allure-pytest-2.9.45\r\ncollecting ... collected 1 item\r\n\r\ntest_statement.py::test_right_statement FAILED [100%]\r\n\r\n================================== FAILURES ===================================\r\n____________________________ test_right_statement _____________________________\r\n\r\nfoo = 1\r\n\r\n def test_right_statement(foo):\r\n> assert foo == (3 + 2) * (6 + 9)\r\n \r\n @t\r\nE assert 1 == 75\r\nE +1\r\nE -75\r\n\r\ntest_statement.py:14: AssertionError\r\n=========================== short test summary info ===========================\r\nFAILED test_statement.py::test_right_statement - assert 1 == 75\r\n============================== 1 failed in 0.12s ==============================\r\n```\r\nAnd the same thing **did not** happen when using python3.7.10\uff1a\r\n```\r\n============================= test session starts =============================\r\nplatform win32 -- Python 3.7.10, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 -- \r\ncachedir: .pytest_cache\r\nrootdir: \r\ncollecting ... collected 1 item\r\n\r\ntest_statement.py::test_right_statement FAILED [100%]\r\n\r\n================================== FAILURES ===================================\r\n____________________________ test_right_statement _____________________________\r\n\r\nfoo = 1\r\n\r\n def test_right_statement(foo):\r\n> assert foo == (3 + 2) * (6 + 9)\r\nE assert 1 == 75\r\nE +1\r\nE -75\r\n\r\ntest_statement.py:14: AssertionError\r\n=========================== short test summary info ===========================\r\nFAILED test_statement.py::test_right_statement - assert 1 == 75\r\n============================== 1 failed in 0.03s ==============================\r\n```\r\nIs there some problems when calculate the statement lineno?\r\n\r\n### pip list \r\n```\r\n$ pip list\r\nPackage Version\r\n------------------ -------\r\natomicwrites 1.4.0\r\nattrs 21.2.0\r\ncolorama 0.4.4\r\nimportlib-metadata 4.8.2\r\niniconfig 1.1.1\r\npackaging 21.3\r\npip 21.3.1\r\npluggy 1.0.0\r\npy 1.11.0\r\npyparsing 3.0.6\r\npytest 6.2.5\r\nsetuptools 59.4.0\r\ntoml 0.10.2\r\ntyping_extensions 4.0.0\r\nzipp 3.6.0\r\n\r\n```\r\n### pytest and operating system versions\r\npytest 6.2.5\r\nWindows 10 \r\nSeems to happen in python 3.9,not 3.7\r\n\n",
18 "version": "7.0",
19 "FAIL_TO_PASS": [
20 "testing/code/test_source.py::test_decorator"
21 ],
22 "PASS_TO_PASS": [
23 "testing/code/test_source.py::TestAccesses::test_getline",
24 "testing/code/test_source.py::TestAccesses::test_getrange",
25 "testing/code/test_source.py::TestAccesses::test_getrange_step_not_supported",
26 "testing/code/test_source.py::TestAccesses::test_iter",
27 "testing/code/test_source.py::TestAccesses::test_len",
28 "testing/code/test_source.py::TestIf::test_body",
29 "testing/code/test_source.py::TestIf::test_elif",
30 "testing/code/test_source.py::TestIf::test_elif_clause",
31 "testing/code/test_source.py::TestIf::test_else",
32 "testing/code/test_source.py::TestSourceParsing::test_getstatement",
33 "testing/code/test_source.py::TestSourceParsing::test_getstatementrange_ast_issue58",
34 "testing/code/test_source.py::TestSourceParsing::test_getstatementrange_bug",
35 "testing/code/test_source.py::TestSourceParsing::test_getstatementrange_bug2",
36 "testing/code/test_source.py::TestSourceParsing::test_getstatementrange_out_of_bounds_py3",
37 "testing/code/test_source.py::TestSourceParsing::test_getstatementrange_triple_quoted",
38 "testing/code/test_source.py::TestSourceParsing::test_getstatementrange_with_syntaxerror_issue7",
39 "testing/code/test_source.py::TestSourceParsing::test_getstatementrange_within_constructs",
40 "testing/code/test_source.py::TestTry::test_body",
41 "testing/code/test_source.py::TestTry::test_else",
42 "testing/code/test_source.py::TestTry::test_except_body",
43 "testing/code/test_source.py::TestTry::test_except_line",
44 "testing/code/test_source.py::TestTryFinally::test_body",
45 "testing/code/test_source.py::TestTryFinally::test_finally",
46 "testing/code/test_source.py::test_code_of_object_instance_with_call",
47 "testing/code/test_source.py::test_comment_and_no_newline_at_end",
48 "testing/code/test_source.py::test_comment_in_statement",
49 "testing/code/test_source.py::test_comments",
50 "testing/code/test_source.py::test_def_online",
51 "testing/code/test_source.py::test_deindent",
52 "testing/code/test_source.py::test_findsource",
53 "testing/code/test_source.py::test_findsource_fallback",
54 "testing/code/test_source.py::test_getfslineno",
55 "testing/code/test_source.py::test_getfuncsource_dynamic",
56 "testing/code/test_source.py::test_getfuncsource_with_multine_string",
57 "testing/code/test_source.py::test_getline_finally",
58 "testing/code/test_source.py::test_getstartingblock_multiline",
59 "testing/code/test_source.py::test_getstartingblock_singleline",
60 "testing/code/test_source.py::test_issue55",
61 "testing/code/test_source.py::test_multiline",
62 "testing/code/test_source.py::test_oneline",
63 "testing/code/test_source.py::test_oneline_and_comment",
64 "testing/code/test_source.py::test_semicolon",
65 "testing/code/test_source.py::test_single_line_else",
66 "testing/code/test_source.py::test_single_line_finally",
67 "testing/code/test_source.py::test_source_fallback",
68 "testing/code/test_source.py::test_source_from_function",
69 "testing/code/test_source.py::test_source_from_inner_function",
70 "testing/code/test_source.py::test_source_from_lines",
71 "testing/code/test_source.py::test_source_from_method",
72 "testing/code/test_source.py::test_source_of_class_at_eof_without_newline",
73 "testing/code/test_source.py::test_source_str_function",
74 "testing/code/test_source.py::test_source_strip_multiline",
75 "testing/code/test_source.py::test_source_strips",
76 "testing/code/test_source.py::test_source_with_decorator"
77 ],
78 "environment_setup_commit": "e2ee3144ed6e241dea8d96215fcdca18b3892551",
79 "patch": "diff --git a/src/_pytest/_code/source.py b/src/_pytest/_code/source.py\n--- a/src/_pytest/_code/source.py\n+++ b/src/_pytest/_code/source.py\n@@ -149,6 +149,11 @@ def get_statement_startend2(lineno: int, node: ast.AST) -> Tuple[int, Optional[i\n values: List[int] = []\n for x in ast.walk(node):\n if isinstance(x, (ast.stmt, ast.ExceptHandler)):\n+ # Before Python 3.8, the lineno of a decorated class or function pointed at the decorator.\n+ # Since Python 3.8, the lineno points to the class/def, so need to include the decorators.\n+ if isinstance(x, (ast.ClassDef, ast.FunctionDef, ast.AsyncFunctionDef)):\n+ for d in x.decorator_list:\n+ values.append(d.lineno - 1)\n values.append(x.lineno - 1)\n for name in (\"finalbody\", \"orelse\"):\n val: Optional[List[ast.stmt]] = getattr(x, name, None)\n",
80 "pr_link": "https://github.com/pytest-dev/pytest/pull/9359"
81 }
82}