1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
import pytest
def test_thread_index_single_thread(pytester: pytest.Pytester) -> None:
pytester.makepyfile("""
def test_thread_index(thread_index):
assert thread_index == 0
""")
result = pytester.runpytest("--parallel-threads=1", "-v")
result.stdout.fnmatch_lines(
[
"*::test_thread_index PASSED*",
]
)
def test_thread_index_num_parallel_threads(pytester: pytest.Pytester) -> None:
pytester.makepyfile("""
def test_thread_index(thread_index, num_parallel_threads):
assert thread_index < num_parallel_threads
""")
result = pytester.runpytest("--parallel-threads=auto", "-v")
result.stdout.fnmatch_lines(
[
"*::test_thread_index PARALLEL PASSED*",
]
)
def test_thread_index_changes_between_tests(pytester: pytest.Pytester) -> None:
# thread_comp is checking if the thread_indexes are equal between threads.
# should fail since thread_indexes should not match.
# test can be improved, since this cannot check if every thread has a
# different thread_index
pytester.makepyfile("""
def test_thread_index(thread_index, thread_comp):
thread_comp(thread_index=thread_index)
""")
result = pytester.runpytest("--parallel-threads=auto", "-v")
result.stdout.fnmatch_lines(
[
"*::test_thread_index PARALLEL FAILED*",
]
)
def test_iteration_index_single_iteration(pytester: pytest.Pytester) -> None:
pytester.makepyfile("""
def test_iteration_index(iteration_index):
assert iteration_index == 0
""")
result = pytester.runpytest("--parallel-threads=auto", "--iterations=1", "-v")
result.stdout.fnmatch_lines(
[
"*::test_iteration_index PARALLEL PASSED*",
]
)
def test_iteration_index_multi_iteration(pytester: pytest.Pytester) -> None:
pytester.makepyfile("""
def test_iteration_index(iteration_index, num_iterations):
assert iteration_index < num_iterations
""")
result = pytester.runpytest("--parallel-threads=1", "--iterations=3", "-v")
result.stdout.fnmatch_lines(
[
"*::test_iteration_index PASSED*",
]
)
def test_iteration_index_multi_iteration_mutli_thread(
pytester: pytest.Pytester,
) -> None:
pytester.makepyfile("""
def test_iteration_index(iteration_index, num_iterations):
assert iteration_index < num_iterations
""")
result = pytester.runpytest("--parallel-threads=auto", "--iterations=3", "-v")
result.stdout.fnmatch_lines(
[
"*::test_iteration_index PARALLEL PASSED*",
]
)
|