Skip to content

Commit

Permalink
fix: run all tests when no tags provided and option is not set (#21)
Browse files Browse the repository at this point in the history
co-authored by: @Stefanhg

Co-authored-by: Sergio Castillo <sergio.lara@elementsinteractive.es>
  • Loading branch information
scastlara and Sergio Castillo committed Apr 7, 2024
1 parent b940631 commit 20867dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pytest_tagging/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_items_to_run(self, tags_to_run, tags_to_exclude, items):
"""
selected_items = set()
deselected_items = set()
if self.config.tags == [] or (self.config.tags is not None and not tags_to_run):
if is_tags_empty(self.config.tags) or (is_tags_option_provided(self.config.tags) and not tags_to_run):
# No tags match the conditions to run
# or we just passed an empty `--tags` options to see them all.
deselected_items.update(items)
Expand All @@ -50,8 +50,10 @@ def get_items_to_run(self, tags_to_run, tags_to_exclude, items):
# Excluding tags takes precendence ove any selection.
if test_tags & tags_to_exclude:
deselected_items.add(item)
elif (self.config.operand is OperandChoices.OR and test_tags & tags_to_run) or (
self.config.operand is OperandChoices.AND and tags_to_run <= test_tags
elif (
not is_tags_option_provided(self.config.tags)
or (self.config.operand is OperandChoices.OR and test_tags & tags_to_run)
or (self.config.operand is OperandChoices.AND and tags_to_run <= test_tags)
):
selected_items.add(item)
else:
Expand All @@ -61,3 +63,11 @@ def get_items_to_run(self, tags_to_run, tags_to_exclude, items):

def get_tags_from_item(item) -> set[str]:
return set(item.get_closest_marker("tags").args) if item.get_closest_marker("tags") else set()


def is_tags_empty(tags: list[str] | None) -> bool:
return tags == []


def is_tags_option_provided(tags: list[str] | None) -> bool:
return tags is not None
7 changes: 7 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
from pytest_tagging.utils import TagCounterThreadSafe


def test_no_tags(pytester):
"""Test that with no tags specified a test is still executed"""
pytester.makepyfile("def test_pass(): pass")
res = pytester.runpytest()
res.assert_outcomes(passed=1)


@pytest.mark.parametrize(
"option, expected_counter",
(
Expand Down

0 comments on commit 20867dc

Please sign in to comment.