Skip to content

makepyfile with a test method + inline_run disables assertion rewriting (?) #4947

Description

@belugame

OS: Ubuntu 16.04, python2.7, pytest 4.3.1

I'm working on a plugin for pytest, therefore I create temporary python files which hold test methods. This however makes the assertion-error report of pytest less human-readable.

pytest_plugins = ["pytester"]
def test_foo(testdir):                                                              
    some_test = """                                                                 
    def test_bar(): pass                                                            
    """                                                                             
    testdir.makepyfile(some_test)                                                   
    testdir.inline_run()                                                            
    assert "abcdefghijk" == "abdcdefghijkl" 

Gives me:

_____________________ test_foo ___________________

testdir = <Testdir local('/tmp/pytest-of-foo/pytest-159/test_foo0')>

    def test_foo(testdir):
        some_test = """
        def test_foo(): pass
        """
        testdir.makepyfile(some_test)
        testdir.inline_run()
>       assert "abcdefghijk" == "abdcdefghijkl"
E       AssertionError: assert 'abcdefghijk' == 'abdcdefghijkl'

When I rename def test_bar to just def bar, I get the expected easy to read error:


>       assert "abcdefghijk" == "abdcdefghijkl"
E       AssertionError: assert 'abcdefghijk' == 'abdcdefghijkl'
E         - abcdefghijk
E         + abdcdefghijkl
E         ?   +         +

So it seems it does not like the test-method in the file. Not sure if this is a bug, or I am using it wrong?

pip list

Package        Version
-------------- -------
atomicwrites   1.3.0  
attrs          19.1.0 
funcsigs       1.0.2  
more-itertools 5.0.0  
pathlib2       2.3.3  
pip            19.0.3 
pluggy         0.9.0  
py             1.8.0  
pytest         4.3.1  
scandir        1.10.0 
setuptools     40.8.0 
six            1.12.0 
wheel          0.33.1 

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: rewriterelated to the assertion rewrite mechanismtype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions