Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing error message with forgotten self #243

Closed
Jasha10 opened this issue Dec 30, 2021 · 1 comment · Fixed by #247
Closed

Confusing error message with forgotten self #243

Jasha10 opened this issue Dec 30, 2021 · 1 comment · Fixed by #247

Comments

@Jasha10
Copy link

Jasha10 commented Dec 30, 2021

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 :)

@smarie smarie closed this as completed in c2a69b8 Jan 2, 2022
@smarie
Copy link
Owner

smarie commented Jan 2, 2022

Thanks for reporting ! I added some extra checks

smarie pushed a commit that referenced this issue Jan 3, 2022
…iring fixtures. Made the test only valid in python 3.
smarie added a commit that referenced this issue Jan 3, 2022
* Completed fix for #243: now also with cases having parameters or requiring fixtures. Made the test only valid in python 3.

* Fixed version flag in develop mode - there was a bug due to the folder refactoring.

* Added support for the new Scopes enum in pytest 7: `fixdef.scopenum` and `callspec._arg2scopenum` are now `fixdef._scope` and `callspec._arg2scope` and contain a `Scope`. Sorting of fixture defs is now done according to the reversed order of Scope enum instances. Not yet tested with pytest-7.0.0rc1. (hopefully) Fixed #241

* Changelog 3.6.7

Co-authored-by: Sylvain MARIE <sylvain.marie@se.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants