Elffuss BraidHub

kikocis/auto-code-rover public

main · 3.3 KiBRawPermalink
1Error message prints extra code line when using assert in python3.9
2<!--
3Thanks for submitting an issue!
4
5Quick check-list while reporting bugs:
6-->
7
8- [x] a detailed description of the bug or problem you are having
9- [x] output of `pip list` from the virtual environment you are using
10- [x] pytest and operating system versions
11- [ ] minimal example if possible
12### Description
13I have a test like this:
14```
15from pytest import fixture
16
17
18def t(foo):
19 return foo
20
21
22@fixture
23def foo():
24 return 1
25
26
27def test_right_statement(foo):
28 assert foo == (3 + 2) * (6 + 9)
29
30 @t
31 def inner():
32 return 2
33
34 assert 2 == inner
35
36
37@t
38def outer():
39 return 2
40```
41The test "test_right_statement" fails at the first assertion,but print extra code (the "t" decorator) in error details, like this:
42
43```
44 ============================= test session starts =============================
45platform win32 -- Python 3.9.6, pytest-6.2.5, py-1.10.0, pluggy-0.13.1 --
46cachedir: .pytest_cache
47rootdir:
48plugins: allure-pytest-2.9.45
49collecting ... collected 1 item
50
51test_statement.py::test_right_statement FAILED [100%]
52
53================================== FAILURES ===================================
54____________________________ test_right_statement _____________________________
55
56foo = 1
57
58 def test_right_statement(foo):
59> assert foo == (3 + 2) * (6 + 9)
60
61 @t
62E assert 1 == 75
63E +1
64E -75
65
66test_statement.py:14: AssertionError
67=========================== short test summary info ===========================
68FAILED test_statement.py::test_right_statement - assert 1 == 75
69============================== 1 failed in 0.12s ==============================
70```
71And the same thing **did not** happen when using python3.7.10:
72```
73============================= test session starts =============================
74platform win32 -- Python 3.7.10, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 --
75cachedir: .pytest_cache
76rootdir:
77collecting ... collected 1 item
78
79test_statement.py::test_right_statement FAILED [100%]
80
81================================== FAILURES ===================================
82____________________________ test_right_statement _____________________________
83
84foo = 1
85
86 def test_right_statement(foo):
87> assert foo == (3 + 2) * (6 + 9)
88E assert 1 == 75
89E +1
90E -75
91
92test_statement.py:14: AssertionError
93=========================== short test summary info ===========================
94FAILED test_statement.py::test_right_statement - assert 1 == 75
95============================== 1 failed in 0.03s ==============================
96```
97Is there some problems when calculate the statement lineno?
98
99### pip list
100```
101$ pip list
102Package Version
103------------------ -------
104atomicwrites 1.4.0
105attrs 21.2.0
106colorama 0.4.4
107importlib-metadata 4.8.2
108iniconfig 1.1.1
109packaging 21.3
110pip 21.3.1
111pluggy 1.0.0
112py 1.11.0
113pyparsing 3.0.6
114pytest 6.2.5
115setuptools 59.4.0
116toml 0.10.2
117typing_extensions 4.0.0
118zipp 3.6.0
119
120```
121### pytest and operating system versions
122pytest 6.2.5
123Windows 10
124Seems to happen in python 3.9,not 3.7
125