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

fix: cannot run nested pytest test classes #1138

Merged

Conversation

aghoward
Copy link
Contributor

In my workflow at work I sometimes have pytest test classes nested two classes deep, but as is I cannot run single tests within the nested test classes. This fixes the issue by looping all parent classes and adding their names to the fully qualified name passed to pytest. Tested locally with the following python pytests:

def foo() -> None:
    return None


def test_foo() -> None:
    assert foo() is None


class TestFoo:
    def test_toplevel_class_test(self) -> None:
        assert foo() is None

    class TestMethods:
        def test_single_nested_level_class_test(self) -> None:
            assert foo() is None

        class TestRealFarIn:
            def test_double_nested_level_class_test(self) -> None:
                assert foo() is None

Each of these tests can be run individually with pyright.singleTest command after this fix.

I'm not 100% sure what your PR process is, so let me know if I did something wrong here. Thanks for your time and your plugin!

@fannheyward
Copy link
Owner

LGTM, fix the formatting issue please.

@aghoward aghoward force-pushed the fix-multiple-pytest-nested-classes branch from 9a72276 to f94d303 Compare February 12, 2025 01:11
@aghoward aghoward force-pushed the fix-multiple-pytest-nested-classes branch from f94d303 to 49d95c1 Compare February 12, 2025 01:15
@fannheyward fannheyward merged commit ab6975f into fannheyward:master Feb 12, 2025
3 checks passed
@fannheyward
Copy link
Owner

Released in v1.1.394

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 this pull request may close these issues.

2 participants