JamesHutchison / pytest-hot-reloading

A hot reloading pytest daemon, implemented as a plugin
MIT License
86 stars 2 forks source link

Update monkeypatch to fix (many) line numbers being off due to decorators #86

Closed JamesHutchison closed 4 months ago

JamesHutchison commented 4 months ago

This is a bit of a complicated problem and is not fully resolved, but this seems to be improvement over the simple adjustment in the previous logic. The old logic was doing a simple shift on the line numbers, and it seemed to fix the problem if a function was lower in the file after a function that had a single decorator.

For example:

@pytest.fixture(autouse=True)
def setup(self):
    ...

def function_with_wrong_line_numbers(self):
    # the off by one fix in the previous code fixed me

In all other cases the line numbers would be wrong. With this new fix, I'm seeing most cases being correct except for multiline decorators, but it's easily fixed by altering the function with the wrong line numbers.

@somedecorator(

)
def this_function_will_offset_line_numbers_by_2(...):
    ...

See https://github.com/breuleux/jurigged/issues/29 for the full issue discussion.