Elffuss BraidHub

kikocis/auto-code-rover public

main · 15.9 KiBRawPermalink
1{
2 "task_id": "pytest-dev__pytest-5413",
3 "setup_info": {
4 "repo_path": "/home/haifeng/projects/reverse-prompt/SWE-bench/testbed/pytest-dev__pytest/setup_pytest-dev__pytest__4.6",
5 "env_name": "setup_pytest-dev__pytest__4.6",
6 "pre_install": [],
7 "install": "python -m pip install -e .",
8 "test_cmd": "pytest -rA testing/code/test_excinfo.py"
9 },
10 "task_info": {
11 "instance_id": "pytest-dev__pytest-5413",
12 "base_commit": "450d2646233c670654744d3d24330b69895bb9d2",
13 "hints_text": "> Any chance the behavior could be changed to eliminate this gotcha?\r\n\r\nWhat do you suggest?\r\n\r\nProxying through to the exceptions `__str__`?\nHi @fiendish,\r\n\r\nIndeed this is a bit confusing.\r\n\r\nCurrently `ExceptionInfo` objects (which is `pytest.raises` returns to the context manager) implements `__str__` like this:\r\n\r\nhttps://github.com/pytest-dev/pytest/blob/9f8b566ea976df3a3ea16f74b56dd6d4909b84ee/src/_pytest/_code/code.py#L537-L542\r\n\r\nI don't see much use for this, I would rather it didn't implement `__str__` at all and let `__repr__` take over, which would show something like:\r\n\r\n```\r\n<ExceptionInfo LookupError tb=10>\r\n```\r\n\r\nWhich makes it more obvious that this is not what the user intended with `str(e)` probably.\r\n\r\nSo I think a good solution is to simply delete the `__str__` method.\r\n\r\nThoughts?\r\n\r\nAlso, @fiendish which Python version are you using?\n> So I think a good solution is to simply delete the `__str__` method.\r\n\r\nMakes sense to me.\r\n\r\n\nPython 3.7.3\r\n\r\nMy ideal outcome would be for str(e) to act the same as str(e.value), but I can understand if that isn't desired.\n> My ideal outcome would be for str(e) to act the same as str(e.value), but I can understand if that isn't desired.\r\n\r\nI understand, but I think it is better to be explicit here, because users might use `print(e)` to see what `e` is, assume it is the exception value, and then get confused later when it actually isn't (an `isinstance` check or accessing `e.args`).\n+1 for deleting the current `__str__` implementation\r\n-1 for proxying it to the underlying `e.value`\r\n\r\nthe `ExceptionInfo` object is not the exception and anything that makes it look more like the exception is just going to add to the confusion",
14 "created_at": "2019-06-06T15:21:20Z",
15 "test_patch": "diff --git a/testing/code/test_excinfo.py b/testing/code/test_excinfo.py\n--- a/testing/code/test_excinfo.py\n+++ b/testing/code/test_excinfo.py\n@@ -333,18 +333,10 @@ def test_excinfo_exconly():\n assert msg.endswith(\"world\")\n \n \n-def test_excinfo_repr():\n+def test_excinfo_repr_str():\n excinfo = pytest.raises(ValueError, h)\n- s = repr(excinfo)\n- assert s == \"<ExceptionInfo ValueError tblen=4>\"\n-\n-\n-def test_excinfo_str():\n- excinfo = pytest.raises(ValueError, h)\n- s = str(excinfo)\n- assert s.startswith(__file__[:-9]) # pyc file and $py.class\n- assert s.endswith(\"ValueError\")\n- assert len(s.split(\":\")) >= 3 # on windows it's 4\n+ assert repr(excinfo) == \"<ExceptionInfo ValueError tblen=4>\"\n+ assert str(excinfo) == \"<ExceptionInfo ValueError tblen=4>\"\n \n \n def test_excinfo_for_later():\n",
16 "repo": "pytest-dev/pytest",
17 "problem_statement": "str() on the pytest.raises context variable doesn't behave same as normal exception catch\nPytest 4.6.2, macOS 10.14.5\r\n\r\n```Python\r\ntry:\r\n raise LookupError(\r\n f\"A\\n\"\r\n f\"B\\n\"\r\n f\"C\"\r\n )\r\nexcept LookupError as e:\r\n print(str(e))\r\n```\r\nprints\r\n\r\n> A\r\n> B\r\n> C\r\n\r\nBut\r\n\r\n```Python\r\nwith pytest.raises(LookupError) as e:\r\n raise LookupError(\r\n f\"A\\n\"\r\n f\"B\\n\"\r\n f\"C\"\r\n )\r\n\r\nprint(str(e))\r\n```\r\n\r\nprints\r\n\r\n> <console>:3: LookupError: A\r\n\r\nIn order to get the full error message, one must do `str(e.value)`, which is documented, but this is a different interaction. Any chance the behavior could be changed to eliminate this gotcha?\r\n\r\n-----\r\n\r\nPip list gives\r\n\r\n```\r\nPackage Version Location\r\n------------------ -------- ------------------------------------------------------\r\napipkg 1.5\r\nasn1crypto 0.24.0\r\natomicwrites 1.3.0\r\nattrs 19.1.0\r\naws-xray-sdk 0.95\r\nboto 2.49.0\r\nboto3 1.9.51\r\nbotocore 1.12.144\r\ncertifi 2019.3.9\r\ncffi 1.12.3\r\nchardet 3.0.4\r\nClick 7.0\r\ncodacy-coverage 1.3.11\r\ncolorama 0.4.1\r\ncoverage 4.5.3\r\ncryptography 2.6.1\r\ndecorator 4.4.0\r\ndocker 3.7.2\r\ndocker-pycreds 0.4.0\r\ndocutils 0.14\r\necdsa 0.13.2\r\nexecnet 1.6.0\r\nfuture 0.17.1\r\nidna 2.8\r\nimportlib-metadata 0.17\r\nipaddress 1.0.22\r\nJinja2 2.10.1\r\njmespath 0.9.4\r\njsondiff 1.1.1\r\njsonpickle 1.1\r\njsonschema 2.6.0\r\nMarkupSafe 1.1.1\r\nmock 3.0.4\r\nmore-itertools 7.0.0\r\nmoto 1.3.7\r\nneobolt 1.7.10\r\nneotime 1.7.4\r\nnetworkx 2.1\r\nnumpy 1.15.0\r\npackaging 19.0\r\npandas 0.24.2\r\npip 19.1.1\r\npluggy 0.12.0\r\nprompt-toolkit 2.0.9\r\npy 1.8.0\r\npy2neo 4.2.0\r\npyaml 19.4.1\r\npycodestyle 2.5.0\r\npycparser 2.19\r\npycryptodome 3.8.1\r\nPygments 2.3.1\r\npyOpenSSL 19.0.0\r\npyparsing 2.4.0\r\npytest 4.6.2\r\npytest-cache 1.0\r\npytest-codestyle 1.4.0\r\npytest-cov 2.6.1\r\npytest-forked 1.0.2\r\npython-dateutil 2.7.3\r\npython-jose 2.0.2\r\npytz 2018.5\r\nPyYAML 5.1\r\nrequests 2.21.0\r\nrequests-mock 1.5.2\r\nresponses 0.10.6\r\ns3transfer 0.1.13\r\nsetuptools 41.0.1\r\nsix 1.11.0\r\nsqlite3worker 1.1.7\r\ntabulate 0.8.3\r\nurllib3 1.24.3\r\nwcwidth 0.1.7\r\nwebsocket-client 0.56.0\r\nWerkzeug 0.15.2\r\nwheel 0.33.1\r\nwrapt 1.11.1\r\nxlrd 1.1.0\r\nxmltodict 0.12.0\r\nzipp 0.5.1\r\n```\n",
18 "version": "4.6",
19 "FAIL_TO_PASS": [
20 "testing/code/test_excinfo.py::test_excinfo_repr_str"
21 ],
22 "PASS_TO_PASS": [
23 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_exc_chain_repr",
24 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_exc_chain_repr_cycle",
25 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_exc_chain_repr_without_traceback[cause-The",
26 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_exc_chain_repr_without_traceback[context-During",
27 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_exc_repr_chain_suppression[explicit_suppress]",
28 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_exc_repr_chain_suppression[from_none]",
29 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions0]",
30 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions10]",
31 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions11]",
32 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions12]",
33 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions13]",
34 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions14]",
35 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions15]",
36 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions16]",
37 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions17]",
38 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions18]",
39 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions19]",
40 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions1]",
41 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions20]",
42 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions21]",
43 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions22]",
44 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions23]",
45 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions2]",
46 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions3]",
47 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions4]",
48 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions5]",
49 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions6]",
50 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions7]",
51 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions8]",
52 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions9]",
53 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_excinfo_addouterr",
54 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_excinfo_reprcrash",
55 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_local",
56 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_local_truncated",
57 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_local_with_error",
58 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_local_with_exception_in_class_property",
59 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_many_line_source_not_existing",
60 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_source",
61 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_source_excinfo",
62 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_source_failing_fullsource",
63 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_source_not_existing",
64 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_traceback_and_excinfo",
65 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_traceback_recursion",
66 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_traceback_tbfilter",
67 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_traceback_with_invalid_cwd",
68 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_tracebackentry_lines",
69 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_tracebackentry_lines2",
70 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_tracebackentry_lines_var_kw_args",
71 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_tracebackentry_no",
72 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_tracebackentry_short",
73 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_reprexcinfo_getrepr",
74 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_reprexcinfo_unicode",
75 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_toterminal_long",
76 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_toterminal_long_filenames",
77 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_toterminal_long_incomplete_source",
78 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_toterminal_long_missing_source",
79 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_traceback_repr_style",
80 "testing/code/test_excinfo.py::TestFormattedExcinfo::test_traceback_short_no_source",
81 "testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_cut",
82 "testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_cut_excludepath",
83 "testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_entries",
84 "testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_entry_getsource",
85 "testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_entry_getsource_in_construct",
86 "testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_filter",
87 "testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_filter_selective[<lambda>-False]",
88 "testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_filter_selective[<lambda>-True]",
89 "testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_filter_selective[tracebackhide2-True]",
90 "testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_filter_selective[tracebackhide3-False]",
91 "testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_getcrashentry",
92 "testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_getcrashentry_empty",
93 "testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_no_recursion_index",
94 "testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_only_specific_recursion_errors",
95 "testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_recursion_index",
96 "testing/code/test_excinfo.py::test_codepath_Queue_example",
97 "testing/code/test_excinfo.py::test_cwd_deleted",
98 "testing/code/test_excinfo.py::test_entrysource_Queue_example",
99 "testing/code/test_excinfo.py::test_exception_repr_extraction_error_on_recursion",
100 "testing/code/test_excinfo.py::test_excinfo_errisinstance",
101 "testing/code/test_excinfo.py::test_excinfo_exconly",
102 "testing/code/test_excinfo.py::test_excinfo_for_later",
103 "testing/code/test_excinfo.py::test_excinfo_getstatement",
104 "testing/code/test_excinfo.py::test_excinfo_no_sourcecode",
105 "testing/code/test_excinfo.py::test_excinfo_simple",
106 "testing/code/test_excinfo.py::test_match_raises_error",
107 "testing/code/test_excinfo.py::test_match_succeeds",
108 "testing/code/test_excinfo.py::test_no_recursion_index_on_recursion_error",
109 "testing/code/test_excinfo.py::test_repr_traceback_with_unicode[None-long]",
110 "testing/code/test_excinfo.py::test_repr_traceback_with_unicode[None-short]",
111 "testing/code/test_excinfo.py::test_repr_traceback_with_unicode[utf16-long]",
112 "testing/code/test_excinfo.py::test_repr_traceback_with_unicode[utf16-short]",
113 "testing/code/test_excinfo.py::test_repr_traceback_with_unicode[utf8-long]",
114 "testing/code/test_excinfo.py::test_repr_traceback_with_unicode[utf8-short]"
115 ],
116 "environment_setup_commit": "d5843f89d3c008ddcb431adbc335b080a79e617e",
117 "patch": "diff --git a/src/_pytest/_code/code.py b/src/_pytest/_code/code.py\n--- a/src/_pytest/_code/code.py\n+++ b/src/_pytest/_code/code.py\n@@ -534,13 +534,6 @@ def getrepr(\n )\n return fmt.repr_excinfo(self)\n \n- def __str__(self):\n- if self._excinfo is None:\n- return repr(self)\n- entry = self.traceback[-1]\n- loc = ReprFileLocation(entry.path, entry.lineno + 1, self.exconly())\n- return str(loc)\n-\n def match(self, regexp):\n \"\"\"\n Check whether the regular expression 'regexp' is found in the string\n",
118 "pr_link": "https://github.com/pytest-dev/pytest/pull/5413"
119 }
120}