Skip to content

Commit

Permalink
Different fixture naming convention
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Park committed Jan 10, 2018
1 parent f50a7aa commit 101b107
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pytest_flakefinder.py
Expand Up @@ -52,9 +52,9 @@ def pytest_generate_tests(self, metafunc):
# This is safer because otherwise test with fixtures might not be setup correctly.
# Parameterization requires the test function to accept the permutation as
# either an argument or depend on it as a fixture. Use fixture so the test
# function signature is not changed. Suffix with timestamp to reduce odds of
# collision with other fixture names.
fixture_name = 'flakefinder-{}'.format(time.time())
# function signature is not changed. Prefix with underscores and suffix with
# function name to reduce odds of collision with other fixture names.
fixture_name = '__flakefinder_{}'.format(metafunc.function.__name__)
metafunc.fixturenames.append(fixture_name)
metafunc.parametrize(
argnames=fixture_name,
Expand Down
30 changes: 30 additions & 0 deletions tests/test_flakefinder.py
Expand Up @@ -197,3 +197,33 @@ class TestAwesome(Base, unittest.TestCase):
for _ in range(pytest_flakefinder.DEFAULT_FLAKE_RUNS)]
)
assert result.ret == 0

def test_fixture_parametrization_with_similar_test_names(testdir):
"""
Ensure tests with the same name in diff namespaces do not cause overloading of
flake runs.
"""
testdir.makepyfile("""
class TestA(object):
def test_something(self):
pass
class TestB(object):
def test_something(self):
pass
def test_something():
pass
""")

# Run pytest.
flags = ['--flake-finder', '-v']
result = testdir.runpytest(*flags)

# Check output.
num_runs = pytest_flakefinder.DEFAULT_FLAKE_RUNS
result.stdout.fnmatch_lines(
['collecting ... collected 150 items'] +
['*::test_something?%d? PASSED*' % i for i in range(num_runs)]
)
assert result.ret == 0

0 comments on commit 101b107

Please sign in to comment.