|
| 1 | +from allure_commons_test.report import AllureReport |
| 2 | + |
| 3 | +from tests.allure_pytest.pytest_runner import AllurePytestRunner |
| 4 | + |
| 5 | + |
| 6 | +FEATURE_CONTENT = ( |
| 7 | + """ |
| 8 | + Feature: Basic allure-pytest-bdd usage |
| 9 | + Scenario: Simple passed example |
| 10 | + Given the preconditions are satisfied |
| 11 | + When the action is invoked |
| 12 | + Then the postconditions are held |
| 13 | + """ |
| 14 | +) |
| 15 | +STEPS_CONTENT = ( |
| 16 | + """ |
| 17 | + from pytest_bdd import scenario, given, when, then |
| 18 | +
|
| 19 | + @scenario("scenario.feature", "Simple passed example") |
| 20 | + def test_scenario_passes(): |
| 21 | + pass |
| 22 | +
|
| 23 | + @given("the preconditions are satisfied") |
| 24 | + def given_the_preconditions_are_satisfied(): |
| 25 | + pass |
| 26 | +
|
| 27 | + @when("the action is invoked") |
| 28 | + def when_the_action_is_invoked(): |
| 29 | + pass |
| 30 | +
|
| 31 | + @then("the postconditions are held") |
| 32 | + def then_the_postconditions_are_held(): |
| 33 | + pass |
| 34 | + """ |
| 35 | +) |
| 36 | + |
| 37 | + |
| 38 | +def test_custom_alluredir(allure_pytest_bdd_runner: AllurePytestRunner): |
| 39 | + alluredir = allure_pytest_bdd_runner.pytester.path |
| 40 | + allure_pytest_bdd_runner.in_memory = False |
| 41 | + |
| 42 | + # run test twice |
| 43 | + # results of all runs must be in the results directory |
| 44 | + for _ in range(2): |
| 45 | + allure_pytest_bdd_runner.run_pytest( |
| 46 | + ("scenario.feature", FEATURE_CONTENT), |
| 47 | + STEPS_CONTENT, |
| 48 | + cli_args=["--alluredir", "allure_results"] |
| 49 | + ) |
| 50 | + assert (alluredir / 'allure_results').exists() |
| 51 | + results = AllureReport(alluredir / 'allure_results') |
| 52 | + assert len(results.test_cases) == 2 |
| 53 | + |
| 54 | + |
| 55 | +def test_clean_alluredir(allure_pytest_bdd_runner: AllurePytestRunner): |
| 56 | + alluredir = allure_pytest_bdd_runner.pytester.path |
| 57 | + allure_pytest_bdd_runner.in_memory = False |
| 58 | + |
| 59 | + # run test twice |
| 60 | + # results of only last runs must be in the results directory |
| 61 | + for _ in range(2): |
| 62 | + allure_pytest_bdd_runner.run_pytest( |
| 63 | + ("scenario.feature", FEATURE_CONTENT), |
| 64 | + STEPS_CONTENT, |
| 65 | + cli_args=["--alluredir", "allure_results", "--clean-alluredir"] |
| 66 | + ) |
| 67 | + results = AllureReport(alluredir / 'allure_results') |
| 68 | + assert len(results.test_cases) == 1 |
| 69 | + |
| 70 | + |
| 71 | +def test_clean_alluredir_with_collectonly(allure_pytest_bdd_runner: AllurePytestRunner): |
| 72 | + alluredir = allure_pytest_bdd_runner.pytester.path |
| 73 | + allure_pytest_bdd_runner.in_memory = False |
| 74 | + |
| 75 | + # run test |
| 76 | + allure_pytest_bdd_runner.run_pytest( |
| 77 | + ("scenario.feature", FEATURE_CONTENT), |
| 78 | + STEPS_CONTENT, |
| 79 | + cli_args=["--alluredir", "allure_results"] |
| 80 | + ) |
| 81 | + results_before_clean = AllureReport(alluredir / 'allure_results') |
| 82 | + # run test with --collectonly |
| 83 | + allure_pytest_bdd_runner.run_pytest( |
| 84 | + ("scenario.feature", FEATURE_CONTENT), |
| 85 | + STEPS_CONTENT, |
| 86 | + cli_args=["--alluredir", "allure_results", "--clean-alluredir", "--collectonly"] |
| 87 | + ) |
| 88 | + # results should be the same |
| 89 | + results_after_clean = AllureReport(alluredir / 'allure_results') |
| 90 | + assert results_before_clean.test_cases == results_after_clean.test_cases |
0 commit comments