Join GitHub today
unexpected indent of test function with docstring #4066
When run test with docstring, FAILURE message indent is unexpected.
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.
But I expected message like below.
I found out the cause is probably
I can reproduce this as well.
While debugging we have the right source:
And here's where it goes awry:
This does appear intentional, but weird.
And actually, here's a great example where the deindent actually introduces a misleading output:
def test_bar(): x = """\ sneaky!""" assert x == ' sneaky!'
if I were to copy paste the code out of that:
>>> x = """\ ... sneaky!""" >>> assert x == ' sneaky!' >>>
it passes! wow!
my inkling is that this is one of those "damned if you do damned if you don't" situations I think we should make the indentation make sense with the source text and remove our fancy tokenize dedent logic and just use
Hehehe I was just debugging this one.
def deindent(lines, offset=None): import textwrap return textwrap.dedent('\n'.join(lines)).split('\n')
With this new implementation I get the expected output:
While the original implementation gives:
But 4 tests in
Want to assume this one @asottile? I won't have much more time to work on this one anyway.
Btw: my impression is that the