Skip to content

unexpected indent of test function with docstring #4066

@515hikaru

Description

@515hikaru

When run test with docstring, FAILURE message indent is unexpected.

For example,

import unittest
class TestSome(unittest.TestCase):

    def test_bar(self):
        """
        This test fails.
        """
        self.assertEqual(1, 3)

run above test with pytest, following message is shown.

    def test_foo(self):
        """
            This test fails.
            """
>       self.assertEqual(1, 3)
E       AssertionError: 1 != 3

But I expected message like below.

    def test_foo(self):
        """
        This test fails.
        """
>       self.assertEqual(1, 3)
E       AssertionError: 1 != 3

I found out the cause is probably tokenize.generate_tokens. (It is used src/_pytest/_code/source.deindent ). However, I do not know how to fix it.

Version

  • macOS 10.14
  • Python: 3.6.5
  • pytest: 3.8.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: reportingrelated to terminal output and user-facing messages and errorstype: 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