-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ignore --clean-alluredir when using --collectonly (#753)
- Loading branch information
Showing
7 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
.tox | ||
.pytest_cache | ||
.python-version | ||
.venv | ||
|
||
*.pyc | ||
*.egg-info | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from allure_commons_test.report import AllureReport | ||
|
||
from tests.allure_pytest.pytest_runner import AllurePytestRunner | ||
|
||
|
||
TEST_FUNC = "def test_first_func(): pass" | ||
|
||
|
||
def test_custom_alluredir(allure_pytest_runner: AllurePytestRunner): | ||
alluredir = allure_pytest_runner.pytester.path | ||
allure_pytest_runner.in_memory = False | ||
|
||
# run test twice | ||
# results of all runs must be in the results directory | ||
for _ in range(2): | ||
allure_pytest_runner.run_pytest( | ||
TEST_FUNC, | ||
cli_args=["--alluredir", "allure_results"] | ||
) | ||
assert (alluredir / 'allure_results').exists() | ||
results = AllureReport(alluredir / 'allure_results') | ||
assert len(results.test_cases) == 2 | ||
|
||
|
||
def test_clean_alluredir(allure_pytest_runner: AllurePytestRunner): | ||
alluredir = allure_pytest_runner.pytester.path | ||
allure_pytest_runner.in_memory = False | ||
|
||
# run test twice | ||
# results of only last runs must be in the results directory | ||
for _ in range(2): | ||
allure_pytest_runner.run_pytest( | ||
TEST_FUNC, | ||
cli_args=["--alluredir", "allure_results", "--clean-alluredir"] | ||
) | ||
results = AllureReport(alluredir / 'allure_results') | ||
assert len(results.test_cases) == 1 | ||
|
||
|
||
def test_clean_alluredir_with_collectonly(allure_pytest_runner: AllurePytestRunner): | ||
alluredir = allure_pytest_runner.pytester.path | ||
allure_pytest_runner.in_memory = False | ||
|
||
# run test | ||
allure_pytest_runner.run_pytest( | ||
TEST_FUNC, | ||
cli_args=["--alluredir", "allure_results"] | ||
) | ||
results_before_clean = AllureReport(alluredir / 'allure_results') | ||
# run test with --collectonly | ||
allure_pytest_runner.run_pytest( | ||
TEST_FUNC, | ||
cli_args=["--alluredir", "allure_results", "--clean-alluredir", "--collectonly"] | ||
) | ||
# results should be the same | ||
results_after_clean = AllureReport(alluredir / 'allure_results') | ||
assert results_before_clean.test_cases == results_after_clean.test_cases |
Empty file.
90 changes: 90 additions & 0 deletions
90
tests/allure_pytest_bdd/acceptance/results/results_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
from allure_commons_test.report import AllureReport | ||
|
||
from tests.allure_pytest.pytest_runner import AllurePytestRunner | ||
|
||
|
||
FEATURE_CONTENT = ( | ||
""" | ||
Feature: Basic allure-pytest-bdd usage | ||
Scenario: Simple passed example | ||
Given the preconditions are satisfied | ||
When the action is invoked | ||
Then the postconditions are held | ||
""" | ||
) | ||
STEPS_CONTENT = ( | ||
""" | ||
from pytest_bdd import scenario, given, when, then | ||
@scenario("scenario.feature", "Simple passed example") | ||
def test_scenario_passes(): | ||
pass | ||
@given("the preconditions are satisfied") | ||
def given_the_preconditions_are_satisfied(): | ||
pass | ||
@when("the action is invoked") | ||
def when_the_action_is_invoked(): | ||
pass | ||
@then("the postconditions are held") | ||
def then_the_postconditions_are_held(): | ||
pass | ||
""" | ||
) | ||
|
||
|
||
def test_custom_alluredir(allure_pytest_bdd_runner: AllurePytestRunner): | ||
alluredir = allure_pytest_bdd_runner.pytester.path | ||
allure_pytest_bdd_runner.in_memory = False | ||
|
||
# run test twice | ||
# results of all runs must be in the results directory | ||
for _ in range(2): | ||
allure_pytest_bdd_runner.run_pytest( | ||
("scenario.feature", FEATURE_CONTENT), | ||
STEPS_CONTENT, | ||
cli_args=["--alluredir", "allure_results"] | ||
) | ||
assert (alluredir / 'allure_results').exists() | ||
results = AllureReport(alluredir / 'allure_results') | ||
assert len(results.test_cases) == 2 | ||
|
||
|
||
def test_clean_alluredir(allure_pytest_bdd_runner: AllurePytestRunner): | ||
alluredir = allure_pytest_bdd_runner.pytester.path | ||
allure_pytest_bdd_runner.in_memory = False | ||
|
||
# run test twice | ||
# results of only last runs must be in the results directory | ||
for _ in range(2): | ||
allure_pytest_bdd_runner.run_pytest( | ||
("scenario.feature", FEATURE_CONTENT), | ||
STEPS_CONTENT, | ||
cli_args=["--alluredir", "allure_results", "--clean-alluredir"] | ||
) | ||
results = AllureReport(alluredir / 'allure_results') | ||
assert len(results.test_cases) == 1 | ||
|
||
|
||
def test_clean_alluredir_with_collectonly(allure_pytest_bdd_runner: AllurePytestRunner): | ||
alluredir = allure_pytest_bdd_runner.pytester.path | ||
allure_pytest_bdd_runner.in_memory = False | ||
|
||
# run test | ||
allure_pytest_bdd_runner.run_pytest( | ||
("scenario.feature", FEATURE_CONTENT), | ||
STEPS_CONTENT, | ||
cli_args=["--alluredir", "allure_results"] | ||
) | ||
results_before_clean = AllureReport(alluredir / 'allure_results') | ||
# run test with --collectonly | ||
allure_pytest_bdd_runner.run_pytest( | ||
("scenario.feature", FEATURE_CONTENT), | ||
STEPS_CONTENT, | ||
cli_args=["--alluredir", "allure_results", "--clean-alluredir", "--collectonly"] | ||
) | ||
# results should be the same | ||
results_after_clean = AllureReport(alluredir / 'allure_results') | ||
assert results_before_clean.test_cases == results_after_clean.test_cases |