|
| 1 | +from allure_commons_test.report import has_test_case |
| 2 | +from allure_commons_test.result import has_step |
| 3 | +from hamcrest import assert_that |
| 4 | + |
| 5 | + |
| 6 | +def test_step_with_thread(allured_testdir): |
| 7 | + allured_testdir.testdir.makepyfile( |
| 8 | + """ |
| 9 | + from concurrent.futures import ThreadPoolExecutor |
| 10 | +
|
| 11 | + import allure |
| 12 | +
|
| 13 | + @allure.step("thread {x}") |
| 14 | + def parallel_step(x=1): |
| 15 | + with allure.step("Sub-step in thread"): |
| 16 | + pass |
| 17 | +
|
| 18 | +
|
| 19 | + def test_thread(): |
| 20 | + with allure.step("Start in thread"): |
| 21 | + with ThreadPoolExecutor(max_workers=2) as executor: |
| 22 | + executor.map(parallel_step, [1, 2]) |
| 23 | + """ |
| 24 | + ) |
| 25 | + |
| 26 | + allured_testdir.run_with_allure() |
| 27 | + |
| 28 | + assert_that(allured_testdir.allure_report, |
| 29 | + has_test_case("test_thread", |
| 30 | + has_step("Start in thread", |
| 31 | + has_step("thread 1", has_step("Sub-step in thread")), |
| 32 | + has_step("thread 2") |
| 33 | + ) |
| 34 | + ) |
| 35 | + ) |
| 36 | + |
| 37 | + |
| 38 | +def test_step_with_reused_threads(allured_testdir): |
| 39 | + allured_testdir.testdir.makepyfile( |
| 40 | + """ |
| 41 | + from concurrent.futures import ThreadPoolExecutor |
| 42 | +
|
| 43 | + import allure |
| 44 | + import random |
| 45 | + from time import sleep |
| 46 | +
|
| 47 | + @allure.step("thread {x}") |
| 48 | + def parallel_step(x=1): |
| 49 | + sleep(random.randint(0, 3)) |
| 50 | +
|
| 51 | + def test_thread(): |
| 52 | + with ThreadPoolExecutor(max_workers=2) as executor: |
| 53 | + executor.map(parallel_step, range(1, 4)) |
| 54 | + with allure.step("Reuse previous threads"): |
| 55 | + with ThreadPoolExecutor(max_workers=2) as executor: |
| 56 | + executor.map(parallel_step, range(1, 4)) |
| 57 | +
|
| 58 | + """ |
| 59 | + ) |
| 60 | + |
| 61 | + allured_testdir.run_with_allure() |
| 62 | + |
| 63 | + assert_that(allured_testdir.allure_report, |
| 64 | + has_test_case("test_thread", |
| 65 | + has_step("thread 1"), |
| 66 | + has_step("thread 2"), |
| 67 | + has_step("thread 3"), |
| 68 | + has_step("Reuse previous threads", |
| 69 | + has_step("thread 1"), |
| 70 | + has_step("thread 2"), |
| 71 | + has_step("thread 3"), |
| 72 | + ), |
| 73 | + ) |
| 74 | + ) |
0 commit comments