Skip to content

Test assertions does not work properly when specifying python_files setting #2121

@nip3o

Description

@nip3o

The user-friendly error messages when test assertion fails in seems to be broken in certain situations. I have created a minimal example project to illustrate this: https://github.com/nip3o/pytest-assert-rewrite-example

When python_files setting is not set, or when the full path to the test file is specified, assertion rewrite works as expected

> pytest tests/test_addition.py
...
    def test_kaka_b():
>       assert 1 + 2 == 4
E       assert (1 + 2) == 4

tests/test_addition.py:6: AssertionError

When adding a python_files setting to pytest.ini, and not specifying the full path to the test file, assertion rewrite does not work.

> pytest
...
    def test_kaka_b():
>       assert 1 + 2 == 4
E       AssertionError

tests/test_addition.py:6: AssertionError

Tested in multiple projects with pytest 3.0.3 as well as 3.0.5. I have included the full output from test runs with debug mode in the repository above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugproblem that needs to be addressedtype: regressionindicates a problem that was introduced in a release which was working previously

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions