-
Notifications
You must be signed in to change notification settings - Fork 23
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
[feature request] Global subtest function #44
Comments
Hi @Conchylicultor, Thanks for the suggestion! Contrary to So while I agree it would be nice, I'm not sure it is possible to implement it without some ugly hacks. I'm leaving this open anyway to review this in the future. 👍 |
@nicoddemus once we can provide contextvars it may be easier, but we should ensure its not quickly turned into a easy abused global im currently leaning towards not enabling it |
In case someone else is interested, I've implemented a small wrapper around subtests which add #45 and #44 (this issue): from etils import epy
with_subtests = epy.testing.with_subtests # Needed to register the fixture for this file
@pytest.mark.usefixtures('with_subtests')
def test_dtype():
with epy.testing.subtests.test("a"): # Do not need to propagate a subtests object in sub-functions
with epy.testing.subtests.test("b"): # Nested subtest is reported as `a/b`
assert 1 == 2 Test reported as As part of https://github.com/google/etils |
Currently, when using subtest, one has to propagate the subtest object in each of the submethods, adding boilerplate:
It would be nice if there was instead a global subtest function which could be called directly. The above code could be rewritten as
Of course, calling
pytest.subtests
would raise an error if executed in a test which does not use the subtest fixture.But this would make it easier to make modular tests function.
If
pytest.subtest
is not possible,import subtests
directly would be great too.The text was updated successfully, but these errors were encountered: