Skip to content

Commit 5b9d37c

Browse files
authored
Ignore --clean-alluredir when using --collectonly (#753)
1 parent 365d2b8 commit 5b9d37c

File tree

7 files changed

+150
-2
lines changed

7 files changed

+150
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
.tox
44
.pytest_cache
55
.python-version
6+
.venv
67

78
*.pyc
89
*.egg-info

allure-pytest-bdd/src/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def clean_up():
2727

2828
def pytest_configure(config):
2929
report_dir = config.option.allure_report_dir
30-
clean = config.option.clean_alluredir
30+
clean = False if config.option.collectonly else config.option.clean_alluredir
3131

3232
if report_dir:
3333
report_dir = os.path.abspath(report_dir)

allure-pytest/src/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def pytest_addhooks(pluginmanager):
151151

152152
def pytest_configure(config):
153153
report_dir = config.option.allure_report_dir
154-
clean = config.option.clean_alluredir
154+
clean = False if config.option.collectonly else config.option.clean_alluredir
155155

156156
test_helper = AllureTestHelper(config)
157157
allure_commons.plugin_manager.register(test_helper)

tests/allure_pytest/acceptance/results/__init__.py

Whitespace-only changes.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from allure_commons_test.report import AllureReport
2+
3+
from tests.allure_pytest.pytest_runner import AllurePytestRunner
4+
5+
6+
TEST_FUNC = "def test_first_func(): pass"
7+
8+
9+
def test_custom_alluredir(allure_pytest_runner: AllurePytestRunner):
10+
alluredir = allure_pytest_runner.pytester.path
11+
allure_pytest_runner.in_memory = False
12+
13+
# run test twice
14+
# results of all runs must be in the results directory
15+
for _ in range(2):
16+
allure_pytest_runner.run_pytest(
17+
TEST_FUNC,
18+
cli_args=["--alluredir", "allure_results"]
19+
)
20+
assert (alluredir / 'allure_results').exists()
21+
results = AllureReport(alluredir / 'allure_results')
22+
assert len(results.test_cases) == 2
23+
24+
25+
def test_clean_alluredir(allure_pytest_runner: AllurePytestRunner):
26+
alluredir = allure_pytest_runner.pytester.path
27+
allure_pytest_runner.in_memory = False
28+
29+
# run test twice
30+
# results of only last runs must be in the results directory
31+
for _ in range(2):
32+
allure_pytest_runner.run_pytest(
33+
TEST_FUNC,
34+
cli_args=["--alluredir", "allure_results", "--clean-alluredir"]
35+
)
36+
results = AllureReport(alluredir / 'allure_results')
37+
assert len(results.test_cases) == 1
38+
39+
40+
def test_clean_alluredir_with_collectonly(allure_pytest_runner: AllurePytestRunner):
41+
alluredir = allure_pytest_runner.pytester.path
42+
allure_pytest_runner.in_memory = False
43+
44+
# run test
45+
allure_pytest_runner.run_pytest(
46+
TEST_FUNC,
47+
cli_args=["--alluredir", "allure_results"]
48+
)
49+
results_before_clean = AllureReport(alluredir / 'allure_results')
50+
# run test with --collectonly
51+
allure_pytest_runner.run_pytest(
52+
TEST_FUNC,
53+
cli_args=["--alluredir", "allure_results", "--clean-alluredir", "--collectonly"]
54+
)
55+
# results should be the same
56+
results_after_clean = AllureReport(alluredir / 'allure_results')
57+
assert results_before_clean.test_cases == results_after_clean.test_cases

tests/allure_pytest_bdd/acceptance/results/__init__.py

Whitespace-only changes.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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

Comments
 (0)