Elffuss BraidHub

kikocis/auto-code-rover public

main · 2.6 KiBRawPermalink
1Wrong path to test file when directory changed in fixture
2Files 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.
3
4test_path_error.py:
5```python
6import os
7import errno
8import shutil
9
10import pytest
11
12
13@pytest.fixture
14def private_dir(): # or (monkeypatch)
15 out_dir = 'ddd'
16
17 try:
18 shutil.rmtree(out_dir)
19 except OSError as ex:
20 if ex.errno != errno.ENOENT:
21 raise
22 os.mkdir(out_dir)
23
24 old_dir = os.getcwd()
25 os.chdir(out_dir)
26 yield out_dir
27 os.chdir(old_dir)
28
29 # Same issue if using:
30 # monkeypatch.chdir(out_dir)
31
32
33def test_show_wrong_path(private_dir):
34 assert False
35```
36
37```diff
38+ Expected: test_path_error.py:29: AssertionError
39- Displayed: ../test_path_error.py:29: AssertionError
40```
41
42The full output is:
43```
44-*- mode: compilation; default-directory: "~/src/pytest_path_error/" -*-
45Compilation started at Fri Jan 10 00:05:52
46
47nox
48nox > Running session test
49nox > Creating virtual environment (virtualenv) using python3.7 in .nox/test
50nox > pip install pytest>=5.3
51nox > pip freeze
52attrs==19.3.0
53importlib-metadata==1.3.0
54more-itertools==8.0.2
55packaging==20.0
56pluggy==0.13.1
57py==1.8.1
58pyparsing==2.4.6
59pytest==5.3.2
60six==1.13.0
61wcwidth==0.1.8
62zipp==0.6.0
63nox > pytest
64================================= test session starts =================================
65platform linux -- Python 3.7.5, pytest-5.3.2, py-1.8.1, pluggy-0.13.1
66rootdir: /home/lhn/src/pytest_path_error
67collected 1 item
68
69test_path_error.py F [100%]
70
71====================================== FAILURES =======================================
72________________________________ test_show_wrong_path _________________________________
73
74private_dir = 'ddd'
75
76 def test_show_wrong_path(private_dir):
77> assert False
78E assert False
79
80../test_path_error.py:29: AssertionError
81================================== 1 failed in 0.03s ==================================
82nox > Command pytest failed with exit code 1
83nox > Session test failed.
84
85Compilation exited abnormally with code 1 at Fri Jan 10 00:06:01
86```
87
88noxfile.py:
89```python
90import nox
91
92@nox.session(python='3.7')
93def test(session):
94 session.install('pytest>=5.3')
95 session.run('pip', 'freeze')
96 session.run('pytest')
97```