-
Notifications
You must be signed in to change notification settings - Fork 41
Closed
Description
In the following example, forgetting to pass a self argument to a pytest case defined in a class results in a confusing error message:
# test_.py
from pytest_cases import parametrize_with_cases
class MyCases:
def case_one(self) -> int:
return 123
def case_two_forgot_self() -> int:
return 456
@parametrize_with_cases(argnames="expected", cases=MyCases)
def test_int(expected: int) -> None:
assert expected in (123, 456)The resulting error could be more clear:
$ pytest test_.py
================================================================== test session starts ==================================================================
platform linux -- Python 3.9.7, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /home/jbss/tmp
plugins: typeguard-2.13.0, cov-3.0.0, lazy-fixture-0.6.3, cases-3.6.5, hydra-core-1.1.1
collected 0 items / 1 error
======================================================================== ERRORS =========================================================================
_______________________________________________________________ ERROR collecting test_.py _______________________________________________________________
too many positional arguments
The above exception was the direct cause of the following exception:
partial object functools.partial(<function MyCases.case_two_forgot_self at 0x7f4057251e50>, <test_.MyCases object at 0x7f40573359a0>) has incorrect arguments
During handling of the above exception, another exception occurred:
Could not determine arguments of functools.partial(<function MyCases.case_two_forgot_self at 0x7f4057251e50>, <test_.MyCases object at 0x7f40573359a0>): partial object functools.partial(<function MyCases.case_two_forgot_self at 0x7f4057251e50>, <test_.MyCases object at 0x7f40573359a0>) has incorrect arguments
================================================================ short test summary info ================================================================
ERROR test_.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
=================================================================== 1 error in 0.10s ====================================================================
It's true that the error message does mention "incorrect arguments".
Maybe polished error messages are a lot to ask from an experimental proof-of-concept library such as this one, but I thought I'd submit this issue with the suggested improvement anyway :)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels