Skip to content

Commit

Permalink
Ignore --clean-alluredir when using --collectonly (#753)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShurikMen committed Dec 7, 2023
1 parent 365d2b8 commit 5b9d37c
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.tox
.pytest_cache
.python-version
.venv

*.pyc
*.egg-info
Expand Down
2 changes: 1 addition & 1 deletion allure-pytest-bdd/src/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def clean_up():

def pytest_configure(config):
report_dir = config.option.allure_report_dir
clean = config.option.clean_alluredir
clean = False if config.option.collectonly else config.option.clean_alluredir

if report_dir:
report_dir = os.path.abspath(report_dir)
Expand Down
2 changes: 1 addition & 1 deletion allure-pytest/src/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def pytest_addhooks(pluginmanager):

def pytest_configure(config):
report_dir = config.option.allure_report_dir
clean = config.option.clean_alluredir
clean = False if config.option.collectonly else config.option.clean_alluredir

test_helper = AllureTestHelper(config)
allure_commons.plugin_manager.register(test_helper)
Expand Down
Empty file.
57 changes: 57 additions & 0 deletions tests/allure_pytest/acceptance/results/results_test.py
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 tests/allure_pytest_bdd/acceptance/results/results_test.py
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

0 comments on commit 5b9d37c

Please sign in to comment.