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

question: skipping cases? #173

Closed
shaunc opened this issue Dec 18, 2020 · 8 comments
Closed

question: skipping cases? #173

shaunc opened this issue Dec 18, 2020 · 8 comments

Comments

@shaunc
Copy link

shaunc commented Dec 18, 2020

Thank you for your library! I am interested in using it to organize the tests for my machine learning library. (I am now using ad-hoc methods to combine fixtures with parametrize.)

Running on some cases, however, is very slow; I don't want to always have to run these cases.

For my tests themselves, I have defined the following decorator:

def skip_slow(test_fct: Callable) -> Callable:
    """
    Skip test unless TEST_SLOW in environment.
    """
    return pytest.mark.skipif(
        not os.environ.get("TEST_SLOW", "").lower() == "true",
        reason="skip slow tests",
    )(test_fct)

Can I use this or something similar with test cases, to optionally skip them?

@shaunc
Copy link
Author

shaunc commented Dec 18, 2020

Oops -- found the doc that answers my question!

@shaunc shaunc closed this as completed Dec 18, 2020
@smarie
Copy link
Owner

smarie commented Dec 18, 2020

Perfect ! Thanks for the feedback @shaunc

@shaunc
Copy link
Author

shaunc commented Dec 18, 2020

Already partially working! Great package; thanks @smarie!

Only thing that tripped me up in the beginning: I was creating my fixtures in modules of a package, whose "init" was importing them. Then when I used fixtures, which depended on other fixtures which were annotated with @parametrize_by_cases, I would get weird "not found" errors -- I thought that chaining case-annotated fixtures wasn't working perhaps.

Of course, the problem turned out to be that new names are generated in module scope, and I needed to import these into the package init. It would be nice to have that in the docs somewhere (in a "warning box" perhaps :)) -- I understand that pytest is magical and pytest_cases doubles down, but putting things at module scope should still be documented.... they could run into other symbols, for instance, and the user wouldn't know what was happening....

@smarie
Copy link
Owner

smarie commented Dec 18, 2020

they could run into other symbols, for instance, and the user wouldn't know what was happening

Actually I have put some safeguards here to generate unique names. But you're right, your point is the same as the one we discussed in #158. @plammens opened #174 for it.

More generally the new engine #170 should remove all hidden fixture creation, as it was a good way to get me started but has a lot of side effects. Thanks for the feedback !

@shaunc
Copy link
Author

shaunc commented Dec 20, 2020

Is there a good workaround for typing these hidden fixtures, btw?

packages/emm/tests/fixtures/__init__.py:2: error: Module 'tests.fixtures.generated_features' has no attribute 'basic'

[and a bunch more such errors from mypy...]

I presume that if I just add them to the module, their names will change. Can I mark them as "to be overridden", somehow?

@smarie
Copy link
Owner

smarie commented Dec 22, 2020

Is there a good workaround for typing these hidden fixtures, btw?

I'm afraid not :( in general I would not recommend using typing/mypy on the test folder, but of course this is a personal decision. If you wish you can open a dedicated issue on this topic (in that case please try to provide a minimal reproducible example) so that users can try to help/have a look

@shaunc
Copy link
Author

shaunc commented Dec 22, 2020

ok ... well for the moment doing # type ignore on fixture import. Hopefully these hidden fixtures will go away. I'll open an issue if necessary on the new implementation in the new year! :)

@smarie
Copy link
Owner

smarie commented Jan 2, 2021

ok, thanks!

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

No branches or pull requests

2 participants