pydiverse / pydiverse.pipedag

A data pipeline orchestration library for rapid iterative development with automatic cache invalidation allowing users to focus writing their tasks in pandas, polars, sqlalchemy, ibis, and alike.
https://pydiversepipedag.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
15 stars 2 forks source link

We still seem to have some problems with '\n' in error message forwarding within flow.run() #25

Closed windiana42 closed 1 year ago

windiana42 commented 1 year ago

Here is a random error which I just received:

FAILED
tests/test_cache/test_basic_cache_invalidation.py:254 (test_change_lazy_query)
(0,) != ()

Expected :()
Actual   :(0,)
<Click to see difference>

__wrapped_mock_method__ = <function NonCallableMock.assert_not_called at 0x7f86fd1a67a0>
args = (<MagicMock name='noop' spec='function' id='140216797158304'>,)
kwargs = {}, __tracebackhide__ = True
msg = "Expected 'noop' to not have been called. Called 1 times.\nCalls: [call(0)].\n\npytest introspection follows:\n\nArgs:\nassert (0,) == ()\n  Left contains one more item: 0\n  Full diff:\n  - ()\n  + (0,)"
__mock_self = <MagicMock name='noop' spec='function' id='140216797158304'>
actual_args = (0,), actual_kwargs = {}
introspection = '\nArgs:\nassert (0,) == ()\n  Left contains one more item: 0\n  Full diff:\n  - ()\n  + (0,)'
@py_assert2 = (), @py_assert1 = None
@py_format4 = '(0,) == ()\n~Left contains one more item: 0\n~Full diff:\n~- ()\n~+ (0,)'

    def assert_wrapper(
        __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any
    ) -> None:
        __tracebackhide__ = True
        try:
>           __wrapped_mock_method__(*args, **kwargs)

../../../.cache/pypoetry/virtualenvs/pydiverse-pipedag-Abc_rarN-py3.10/lib/python3.10/site-packages/pytest_mock/plugin.py:444:
NMAC427 commented 1 year ago

This is completely expected. The exception you see is raised by the pytest-mock library. Its formating has nothing to do with PipeDAG.

You can replicate the same error message by running the following piece of code with pytest:

def test_mock_assert(mocker):
    class Foo:
        def fn(self, x):
            return f"x = {x}"

    obj = Foo()
    spy = mocker.spy(obj, "fn")

    obj.fn("Test")
    spy.assert_not_called()
windiana42 commented 1 year ago

@NMAC427 I think pytest is great technology. But it makes development -- in case you know how to replicate what it does as library or in user space -- not always easier.

windiana42 commented 1 year ago

Even the call-stack is plain wrong: (line 254 is 1 blank line before test function)

tests/test_cache/test_basic_cache_invalidation.py:254 (test_change_lazy_query)
(   x
0  1, 'x') != ()
NMAC427 commented 1 year ago

Even the call-stack is plain wrong: (line 254 is 1 blank line before test function)

tests/test_cache/test_basic_cache_invalidation.py:254 (test_change_lazy_query)
(   x
0  1, 'x') != ()

I believe that this is an issue with PyCharm. If I run a failing test case that uses the pytest-mock asserts using PyCharm, I get the exact same behaviour of getting the wrong line number. However, when I call pytest directly from the command line, I get a much better traceback with correct line numbers.

windiana42 commented 1 year ago

Good to know... I can confirm it works on command line.