Skip to content

Commit 7b0d2aa

Browse files
committed
test(fill): add tests for dir deletion and html output if no tests
1 parent 3579ffb commit 7b0d2aa

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

src/pytest_plugins/filler/tests/test_filler.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,103 @@ def test_fixture_output_based_on_command_line_args(
624624
assert properties["build"] == build_name
625625

626626

627+
test_module_no_matching_tests = textwrap.dedent(
628+
"""\
629+
import pytest
630+
631+
from ethereum_test_tools import Account, Environment, TestAddress, Transaction
632+
633+
@pytest.mark.valid_from("Paris")
634+
def test_will_not_match_filter(state_test):
635+
state_test(env=Environment(),
636+
pre={TestAddress: Account(balance=1_000_000)}, post={}, tx=Transaction())
637+
"""
638+
)
639+
640+
641+
def test_no_tests_collected_deletes_output_directory(testdir, default_t8n):
642+
"""
643+
Test that when no tests are collected/run, the output directory is deleted.
644+
"""
645+
tests_dir = testdir.mkdir("tests")
646+
647+
test_module = tests_dir.join("test_no_match.py")
648+
test_module.write(test_module_no_matching_tests)
649+
650+
testdir.copy_example(name="src/cli/pytest_commands/pytest_ini_files/pytest-fill.ini")
651+
args = [
652+
"-c",
653+
"pytest-fill.ini",
654+
"-v",
655+
"--t8n-server-url",
656+
default_t8n.server_url,
657+
"-k",
658+
"no_such_test_contains_this_filter", # Filter that won't match any test
659+
]
660+
661+
result = testdir.runpytest(*args)
662+
result.assert_outcomes(
663+
passed=0,
664+
failed=0,
665+
skipped=0,
666+
errors=0,
667+
)
668+
669+
# Check that no tests were selected (all were deselected)
670+
assert "0 selected" in result.stdout.str()
671+
672+
# The output directory should be deleted when no tests ran
673+
output_dir = Path(default_output_directory()).absolute()
674+
assert not output_dir.exists(), (
675+
f"Output directory {output_dir} should have been deleted when no tests ran"
676+
)
677+
678+
679+
def test_html_report_message_suppressed_when_no_tests_ran(testdir, default_t8n):
680+
"""
681+
Test that the HTML report message is suppressed when no tests are collected/run.
682+
"""
683+
tests_dir = testdir.mkdir("tests")
684+
685+
test_module = tests_dir.join("test_no_match.py")
686+
test_module.write(test_module_no_matching_tests)
687+
688+
testdir.copy_example(name="src/cli/pytest_commands/pytest_ini_files/pytest-fill.ini")
689+
args = [
690+
"-c",
691+
"pytest-fill.ini",
692+
"-v",
693+
"--t8n-server-url",
694+
default_t8n.server_url,
695+
"-k",
696+
"no_such_test_contains_this_filter", # Filter that won't match any test
697+
]
698+
699+
result = testdir.runpytest(*args)
700+
result.assert_outcomes(
701+
passed=0,
702+
failed=0,
703+
skipped=0,
704+
errors=0,
705+
)
706+
707+
# Check that no tests were selected (all were deselected)
708+
assert "0 selected" in result.stdout.str()
709+
710+
# The HTML report message should NOT be present when no tests ran
711+
# (even though HTML reporting is enabled, the message should be suppressed)
712+
stdout_str = result.stdout.str()
713+
assert "Generated html report:" not in stdout_str, (
714+
"HTML report message should be suppressed when no tests ran"
715+
)
716+
717+
# The output directory should still be deleted when no tests ran
718+
output_dir = Path(default_output_directory()).absolute()
719+
assert not output_dir.exists(), (
720+
f"Output directory {output_dir} should have been deleted when no tests ran"
721+
)
722+
723+
627724
test_module_environment_variables = textwrap.dedent(
628725
"""\
629726
import pytest

0 commit comments

Comments
 (0)