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