coady / multimethod

Multiple argument dispatching.
https://coady.github.io/multimethod
Other
277 stars 24 forks source link

removing __init__.py from tests makes test_methods.py::test_dispatch_exception fail #71

Closed francesco-ballarin closed 2 years ago

francesco-ballarin commented 2 years ago

Hi, I noticed that removing __init__.py from the tests folder causes

========================================================== FAILURES ==========================================================
__________________________________________________ test_dispatch_exception ___________________________________________________

    def test_dispatch_exception():
        @multimethod
        def temp(x: int, y):
            return "int"

        @multimethod
        def temp(x: int, y: float):
            return "int, float"

        @multimethod
        def temp(x: bool):
            return "bool"

        @multimethod
        def temp(x: int, y: object):
            return "int, object"

        with pytest.raises(DispatchError, match="test_methods.py"):
            # invalid number of args, check source file is part of the exception args
            temp(1)
>       assert temp(1, y=1.0) == "int"
E       AssertionError: assert 'int, object' == 'int'
E         - int
E         + int, object

test_methods.py:293: AssertionError
================================================== short test summary info ===================================================
FAILED test_methods.py::test_dispatch_exception - AssertionError: assert 'int, object' == 'int'
================================================ 1 failed, 10 passed in 0.09s ================================================

My python version is 3.10, and I am on the latest pypi release with a manual application of 857e4e98299d55fe7097238eae7179287248913f

coady commented 2 years ago

It's not reproducing for me, but why is this a goal?

% rm tests/__init__.py
% python3 -m pytest -q
.......................                                                      [100%]
23 passed in 0.02s
francesco-ballarin commented 2 years ago

I've reinstalled from the main branch and I confirm the issue is fixed.

There wasn't really any goal: while preparing a test for the other issue I opened, I was copying files outside the repo to edit them, and saw this issue.

coady commented 2 years ago

Thanks.

For future readers: this project predates the standardizing of running libraries as a script (python3 -m pytest vs pytest). Making tests a package used to help with paths and imports. It shouldn't be necessary (nor harmful though) anymore.