pytest-subtests icon indicating copy to clipboard operation
pytest-subtests copied to clipboard

Reports of nested test

Open Conchylicultor opened this issue 3 years ago • 3 comments

Currently:

def test_abc(subtests):
    with subtests.test("a"):
        with subtests.test("b"):
            assert 1 == 2

Is reported as:

___________test_abc [b] ___________

It would be nice if it was reported as:

___________ test_abc [a/b] ___________

This is especially useful when calling the same function from within multiple sub-tests, when the same <name> can be used in multiple subtests.test(<name>), but in different scopes.

Conchylicultor avatar Jul 05 '21 09:07 Conchylicultor

Makes sense, thanks for the suggestion!

nicoddemus avatar Jul 05 '21 11:07 nicoddemus

This is definitely a must have!

plaffitt avatar Dec 15 '21 16:12 plaffitt

In case someone else is interested, I've implemented a small wrapper around subtests which add https://github.com/pytest-dev/pytest-subtests/issues/44 and https://github.com/pytest-dev/pytest-subtests/issues/45 (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 ___________ test_abc [a/b] ___________

As part of https://github.com/google/etils

Conchylicultor avatar Sep 08 '22 14:09 Conchylicultor