Skip to content

Commit 3921d94

Browse files
committed
test: use new MarkMatcher.from_markers method & register test markers
1 parent 6dd8ad6 commit 3921d94

File tree

2 files changed

+12
-29
lines changed

2 files changed

+12
-29
lines changed

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@ markers = [
358358
"foo",
359359
"bar",
360360
"baz",
361+
"number_mark",
362+
"builtin_matchers_mark",
363+
"str_mark",
361364
# conftest.py reorders tests moving slow ones to the end of the list
362365
"slow",
363366
# experimental mark for all tests using pexpect

testing/test_mark_expression.py

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
from __future__ import annotations
22

3-
import collections
43
from typing import Callable
54
from typing import cast
65

76
from _pytest.mark import MarkMatcher
8-
from _pytest.mark import structures
97
from _pytest.mark.expression import Expression
108
from _pytest.mark.expression import MatcherCall
119
from _pytest.mark.expression import ParseError
@@ -241,33 +239,15 @@ def test_invalid_kwarg_name_or_value( # TODO: move to `test_syntax_errors` ?
241239

242240
@pytest.fixture(scope="session")
243241
def mark_matcher() -> MarkMatcher:
244-
markers = []
245-
mark_name_mapping = collections.defaultdict(list)
246-
247-
def create_marker(name: str, kwargs: dict[str, object]) -> structures.Mark:
248-
return structures.Mark(name=name, args=tuple(), kwargs=kwargs, _ispytest=True)
249-
250-
markers.append(create_marker("number_mark", {"a": 1, "b": 2, "c": 3, "d": 999_999}))
251-
markers.append(
252-
create_marker("builtin_matchers_mark", {"x": True, "y": False, "z": None})
253-
)
254-
markers.append(
255-
create_marker(
256-
"str_mark",
257-
{
258-
"m": "M",
259-
"space": "with space",
260-
"aaאבגדcc": "aaאבגדcc",
261-
"אבגד": "אבגד",
262-
"empty": "",
263-
},
264-
)
265-
)
266-
267-
for marker in markers:
268-
mark_name_mapping[marker.name].append(marker)
269-
270-
return MarkMatcher(mark_name_mapping)
242+
markers = [
243+
pytest.mark.number_mark(a=1, b=2, c=3, d=999_999).mark,
244+
pytest.mark.builtin_matchers_mark(x=True, y=False, z=None).mark,
245+
pytest.mark.str_mark(
246+
m="M", space="with space", empty="", aaאבגדcc="aaאבגדcc", אבגד="אבגד"
247+
).mark,
248+
]
249+
250+
return MarkMatcher.from_markers(markers)
271251

272252

273253
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)