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

Tests parametrized with a generator expression are not collecting as expected in an inherited test class #5739

Open
ptpan opened this issue Aug 14, 2019 · 1 comment
Labels
topic: collection related to the collection phase topic: parametrize related to @pytest.mark.parametrize type: enhancement new feature or API change, should be merged into features branch

Comments

@ptpan
Copy link

ptpan commented Aug 14, 2019

The following tests

class TestBase:
  def run_test( a, b ):
    assert 0 <= a + b <= 2

  @pytest.mark.parametrize(
    "a, b",
    product([0, 1], [0, 1])
  )
  def test( s, a, b ):
    s.run_test( a, b )

class TestDerived( TestBase ):
  def run_test( a, b ):
    assert a == 0 or a == 1
    assert b == 0 or b == 1

are collected as

  <Class TestBase>
      <Function test[0-0]>
      <Function test[0-1]>
      <Function test[1-0]>
      <Function test[1-1]>
  <Class TestDerived>
      <Function test[a0-b0]>

where as the desired collection result is

  <Class TestBase>
      <Function test[0-0]>
      <Function test[0-1]>
      <Function test[1-0]>
      <Function test[1-1]>
  <Class TestDerived>
      <Function test[0-0]>
      <Function test[0-1]>
      <Function test[1-0]>
      <Function test[1-1]>

Explicitly converting the generator expression into a list yields the expected result.

Pytest-related packages

pytest             5.0.1
pytest-cov         2.7.1
pytest-forked      1.0.2
pytest-xdist       1.29.0

I can reproduce this problem with Python 3.6.8 on CentOS and Python 3.7.0 on MacOS.

@RonnyPfannschmidt
Copy link
Member

Pytest should warn about that, it's always a mistake to reuse a consumable collection

@Zac-HD Zac-HD added topic: collection related to the collection phase topic: parametrize related to @pytest.mark.parametrize type: enhancement new feature or API change, should be merged into features branch labels Aug 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: collection related to the collection phase topic: parametrize related to @pytest.mark.parametrize type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

No branches or pull requests

3 participants