-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Labels
topic: rewriterelated to the assertion rewrite mechanismrelated to the assertion rewrite mechanism
Description
- a detailed description of the bug or problem you are having
- output of
pip list
from the virtual environment you are using - pytest and operating system versions
- minimal example if possible
Description
I have a test like this:
from pytest import fixture
def t(foo):
return foo
@fixture
def foo():
return 1
def test_right_statement(foo):
assert foo == (3 + 2) * (6 + 9)
@t
def inner():
return 2
assert 2 == inner
@t
def outer():
return 2
The test "test_right_statement" fails at the first assertion,but print extra code (the "t" decorator) in error details, like this:
============================= test session starts =============================
platform win32 -- Python 3.9.6, pytest-6.2.5, py-1.10.0, pluggy-0.13.1 --
cachedir: .pytest_cache
rootdir:
plugins: allure-pytest-2.9.45
collecting ... collected 1 item
test_statement.py::test_right_statement FAILED [100%]
================================== FAILURES ===================================
____________________________ test_right_statement _____________________________
foo = 1
def test_right_statement(foo):
> assert foo == (3 + 2) * (6 + 9)
@t
E assert 1 == 75
E +1
E -75
test_statement.py:14: AssertionError
=========================== short test summary info ===========================
FAILED test_statement.py::test_right_statement - assert 1 == 75
============================== 1 failed in 0.12s ==============================
And the same thing did not happen when using python3.7.10:
============================= test session starts =============================
platform win32 -- Python 3.7.10, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 --
cachedir: .pytest_cache
rootdir:
collecting ... collected 1 item
test_statement.py::test_right_statement FAILED [100%]
================================== FAILURES ===================================
____________________________ test_right_statement _____________________________
foo = 1
def test_right_statement(foo):
> assert foo == (3 + 2) * (6 + 9)
E assert 1 == 75
E +1
E -75
test_statement.py:14: AssertionError
=========================== short test summary info ===========================
FAILED test_statement.py::test_right_statement - assert 1 == 75
============================== 1 failed in 0.03s ==============================
Is there some problems when calculate the statement lineno?
pip list
$ pip list
Package Version
------------------ -------
atomicwrites 1.4.0
attrs 21.2.0
colorama 0.4.4
importlib-metadata 4.8.2
iniconfig 1.1.1
packaging 21.3
pip 21.3.1
pluggy 1.0.0
py 1.11.0
pyparsing 3.0.6
pytest 6.2.5
setuptools 59.4.0
toml 0.10.2
typing_extensions 4.0.0
zipp 3.6.0
pytest and operating system versions
pytest 6.2.5
Windows 10
Seems to happen in python 3.9,not 3.7
Metadata
Metadata
Assignees
Labels
topic: rewriterelated to the assertion rewrite mechanismrelated to the assertion rewrite mechanism