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

VS Code Python Extension Compatibility #184

Open
eleanorjboyd opened this issue Jan 7, 2025 · 1 comment
Open

VS Code Python Extension Compatibility #184

eleanorjboyd opened this issue Jan 7, 2025 · 1 comment

Comments

@eleanorjboyd
Copy link

Hello! I am a maintainer for the python for VS Code extension. I was investigating getting pytest-subtest to work correctly in the extension as outline in this issue and had some questions which I was looking for some help on.

here's the example Im working with

def test(subtests):
    with subtests.test(msg="First subtest"):
        assert 1 == 1
    with subtests.test(msg="Second subtest"):
        assert 2 == 1

output / outcome on running from the terminal:

test_subtest.py::test [First subtest] SUBPASS                                                                                                [100%]
test_subtest.py::test [Second subtest] SUBFAIL                                                                                               [100%]
test_subtest.py::test PASSED                                                                                                                 [100%]
  1. Do subtests get their own callable test ids? Currently I allow the "run" functionality in the sidebar of VS Code seen in this screenshot by calling a test by its specific id but wasn't able to find if a subtest has a specific one that was unique from its parent
Image
  1. Why does the parent test test_subtest.py::test pass if one of the subtests fails?

  2. Finally just curious what your thoughts are on ideal behavior. In my mind it would mirror subtests in unittest as it works now in vscode which is the parent node test_subtest.py::test is displayed in the tree on test discovery, and the children nodes are added to the tree after run (since this is when they are "known").

after discovery:
Image

after run:
Image

Thanks!

@nicoddemus
Copy link
Member

Hi @eleanorjboyd,

Awesome that you are working on this integration with VS Code!

Do subtests get their own callable test ids? Currently I allow the "run" functionality in the sidebar of VS Code seen in this screenshot by calling a test by its specific id but wasn't able to find if a subtest has a specific one that was unique from its parent

They do not, and is not really possible to only execute a subtest individually - you need to execute the parent test, and all the subtests will run as result.

Why does the parent test test_subtest.py::test pass if one of the subtests fails?

That's kind of quirk on how the hooks work today -- while a subtest might fail, the "rest" of the parent test might still pass, consider:

def test(subtests):
    with subtests.test(msg="First subtest"):
        assert 2 == 1
    assert 1 == 1

If the subtest fails but test passes, means the asserts outside the subtests.test blocks passed.

It is not ideal, perhaps we can change this in the future (there's related discussion in #11).

Finally just curious what your thoughts are on ideal behavior.

Yes that looks great!

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