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

Is there a way to select which subtest to run? #100

Open
BowenBao opened this issue Jun 19, 2023 · 11 comments
Open

Is there a way to select which subtest to run? #100

BowenBao opened this issue Jun 19, 2023 · 11 comments
Labels
question Further information is requested

Comments

@BowenBao
Copy link

Like what pytest -k <pattern> does, but on subtest level.

@nicoddemus
Copy link
Member

Hi @BowenBao,

This is not supported today, also I'm not sure how it could be made to work, given the user code that drives the subtests that are executed.

@nicoddemus nicoddemus added the question Further information is requested label Jun 20, 2023
@andre-qumulo
Copy link

@nicoddemus could you provide a little more context on this?

I'm wondering if there's a way to pass an external value into a pytest test that would then control is the subtest is ran?

My line of thought from your comment is that we could do something along the lines of:

class Tests(unittest.TestCase):
    def test(self) -> None:
          if 'subtest1' in tests_to_run:
               with self.subtest('subtest1'):
                      self.subtest_1()
          if 'subtest2' in tests_to_run:
               with self.subtest('subtest2'):
                      self.subtest_2()

I can't think of how we'd pass in tests_to_run to the unit test outside of an environment variable.

@RonnyPfannschmidt
Copy link
Member

This is outside of the scope of subtests

@andre-qumulo
Copy link

@RonnyPfannschmidt Ok, could you at least point me in the right direction? It seems like by using subtests we're losing a valuable developer feature from pytest.

@RonnyPfannschmidt
Copy link
Member

Subtests are not tests, they are part of a test

Nobody ever proposed/implemented a safe mechanism for selecting them and

@andre-qumulo
Copy link

Ok, that still wasn't my question. My question was how do we pass external information to pytests. Do you happen to have a direction to suggest?

@nicoddemus
Copy link
Member

@andre-qumulo depends on where the information comes from... do you mean from the command-line? Perhaps a concrete example of how you want to pass that information would be helpful.

@andre-qumulo
Copy link

@nicoddemus my challenge is that I'm not familiar enough with how information is typically passed to unit tests outside of environment variables

@nicoddemus
Copy link
Member

Sorry, I was not clear: I'm not asking you how you think it should be implemented, rather asking you how you would like to "use" this feature.

For example you posted:

 if 'subtest1' in tests_to_run:
     with self.subtest('subtest1'):
            self.subtest_1()

That's OK, but how do you, as a user, want that to pass that subtest1 downstream so the test can see it.

@andre-qumulo
Copy link

That's the part I'm unclear on personally. I don't see a clear way to pass in additional custom arguments via the pytest commandline: https://docs.pytest.org/en/6.2.x/usage.html#getting-help-on-version-option-names-environment-variables I am curious if you know of any ways.

@nicoddemus
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants