| 1 | { |
| 2 | "task_id": "pytest-dev__pytest-7220", |
| 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_nodes.py" |
| 9 | }, |
| 10 | "task_info": { |
| 11 | "instance_id": "pytest-dev__pytest-7220", |
| 12 | "base_commit": "56bf819c2f4eaf8b36bd8c42c06bb59d5a3bfc0f", |
| 13 | "hints_text": "", |
| 14 | "created_at": "2020-05-16T14:57:17Z", |
| 15 | "test_patch": "diff --git a/testing/test_nodes.py b/testing/test_nodes.py\n--- a/testing/test_nodes.py\n+++ b/testing/test_nodes.py\n@@ -58,3 +58,30 @@ class FakeSession:\n \n outside = py.path.local(\"/outside\")\n assert nodes._check_initialpaths_for_relpath(FakeSession, outside) is None\n+\n+\n+def test_failure_with_changed_cwd(testdir):\n+ \"\"\"\n+ Test failure lines should use absolute paths if cwd has changed since\n+ invocation, so the path is correct (#6428).\n+ \"\"\"\n+ p = testdir.makepyfile(\n+ \"\"\"\n+ import os\n+ import pytest\n+\n+ @pytest.fixture\n+ def private_dir():\n+ out_dir = 'ddd'\n+ os.mkdir(out_dir)\n+ old_dir = os.getcwd()\n+ os.chdir(out_dir)\n+ yield out_dir\n+ os.chdir(old_dir)\n+\n+ def test_show_wrong_path(private_dir):\n+ assert False\n+ \"\"\"\n+ )\n+ result = testdir.runpytest()\n+ result.stdout.fnmatch_lines([str(p) + \":*: AssertionError\", \"*1 failed in *\"])\n", |
| 16 | "repo": "pytest-dev/pytest", |
| 17 | "problem_statement": "Wrong path to test file when directory changed in fixture\nFiles are shown as relative to new directory when working directory is changed in a fixture. This makes it impossible to jump to the error as the editor is unaware of the directory change. The displayed directory should stay relative to the original directory.\r\n\r\ntest_path_error.py:\r\n```python\r\nimport os\r\nimport errno\r\nimport shutil\r\n\r\nimport pytest\r\n\r\n\r\n@pytest.fixture\r\ndef private_dir(): # or (monkeypatch)\r\n out_dir = 'ddd'\r\n\r\n try:\r\n shutil.rmtree(out_dir)\r\n except OSError as ex:\r\n if ex.errno != errno.ENOENT:\r\n raise\r\n os.mkdir(out_dir)\r\n\r\n old_dir = os.getcwd()\r\n os.chdir(out_dir)\r\n yield out_dir\r\n os.chdir(old_dir)\r\n\r\n # Same issue if using:\r\n # monkeypatch.chdir(out_dir)\r\n\r\n\r\ndef test_show_wrong_path(private_dir):\r\n assert False\r\n```\r\n\r\n```diff\r\n+ Expected: test_path_error.py:29: AssertionError\r\n- Displayed: ../test_path_error.py:29: AssertionError\r\n```\r\n\r\nThe full output is:\r\n```\r\n-*- mode: compilation; default-directory: \"~/src/pytest_path_error/\" -*-\r\nCompilation started at Fri Jan 10 00:05:52\r\n\r\nnox\r\nnox > Running session test\r\nnox > Creating virtual environment (virtualenv) using python3.7 in .nox/test\r\nnox > pip install pytest>=5.3\r\nnox > pip freeze\r\nattrs==19.3.0\r\nimportlib-metadata==1.3.0\r\nmore-itertools==8.0.2\r\npackaging==20.0\r\npluggy==0.13.1\r\npy==1.8.1\r\npyparsing==2.4.6\r\npytest==5.3.2\r\nsix==1.13.0\r\nwcwidth==0.1.8\r\nzipp==0.6.0\r\nnox > pytest \r\n================================= test session starts =================================\r\nplatform linux -- Python 3.7.5, pytest-5.3.2, py-1.8.1, pluggy-0.13.1\r\nrootdir: /home/lhn/src/pytest_path_error\r\ncollected 1 item \r\n\r\ntest_path_error.py F [100%]\r\n\r\n====================================== FAILURES =======================================\r\n________________________________ test_show_wrong_path _________________________________\r\n\r\nprivate_dir = 'ddd'\r\n\r\n def test_show_wrong_path(private_dir):\r\n> assert False\r\nE assert False\r\n\r\n../test_path_error.py:29: AssertionError\r\n================================== 1 failed in 0.03s ==================================\r\nnox > Command pytest failed with exit code 1\r\nnox > Session test failed.\r\n\r\nCompilation exited abnormally with code 1 at Fri Jan 10 00:06:01\r\n```\r\n\r\nnoxfile.py:\r\n```python\r\nimport nox\r\n\r\n@nox.session(python='3.7')\r\ndef test(session):\r\n session.install('pytest>=5.3')\r\n session.run('pip', 'freeze')\r\n session.run('pytest')\r\n```\n", |
| 18 | "version": "5.4", |
| 19 | "FAIL_TO_PASS": [ |
| 20 | "testing/test_nodes.py::test_failure_with_changed_cwd" |
| 21 | ], |
| 22 | "PASS_TO_PASS": [ |
| 23 | "testing/test_nodes.py::test__check_initialpaths_for_relpath", |
| 24 | "testing/test_nodes.py::test_ischildnode[--True]", |
| 25 | "testing/test_nodes.py::test_ischildnode[-foo-True]", |
| 26 | "testing/test_nodes.py::test_ischildnode[-foo/bar-True]", |
| 27 | "testing/test_nodes.py::test_ischildnode[-foo/bar::TestBaz-True]", |
| 28 | "testing/test_nodes.py::test_ischildnode[foo-food-False]", |
| 29 | "testing/test_nodes.py::test_ischildnode[foo/bar-foo/bar::TestBop-True]", |
| 30 | "testing/test_nodes.py::test_ischildnode[foo/bar::TestBaz-foo/bar-False]", |
| 31 | "testing/test_nodes.py::test_ischildnode[foo/bar::TestBaz-foo/bar::TestBop-False]", |
| 32 | "testing/test_nodes.py::test_node_from_parent_disallowed_arguments", |
| 33 | "testing/test_nodes.py::test_std_warn_not_pytestwarning" |
| 34 | ], |
| 35 | "environment_setup_commit": "678c1a0745f1cf175c442c719906a1f13e496910", |
| 36 | "patch": "diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py\n--- a/src/_pytest/nodes.py\n+++ b/src/_pytest/nodes.py\n@@ -29,6 +29,7 @@\n from _pytest.mark.structures import MarkDecorator\n from _pytest.mark.structures import NodeKeywords\n from _pytest.outcomes import fail\n+from _pytest.pathlib import Path\n from _pytest.store import Store\n \n if TYPE_CHECKING:\n@@ -361,9 +362,14 @@ def _repr_failure_py(\n else:\n truncate_locals = True\n \n+ # excinfo.getrepr() formats paths relative to the CWD if `abspath` is False.\n+ # It is possible for a fixture/test to change the CWD while this code runs, which\n+ # would then result in the user seeing confusing paths in the failure message.\n+ # To fix this, if the CWD changed, always display the full absolute path.\n+ # It will be better to just always display paths relative to invocation_dir, but\n+ # this requires a lot of plumbing (#6428).\n try:\n- os.getcwd()\n- abspath = False\n+ abspath = Path(os.getcwd()) != Path(self.config.invocation_dir)\n except OSError:\n abspath = True\n \n", |
| 37 | "pr_link": "https://github.com/pytest-dev/pytest/pull/7220" |
| 38 | } |
| 39 | } |