Skip to content

Commit

Permalink
Utilize more_itertools to consolidate logic when collecting marks.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jul 1, 2023
1 parent b77d0de commit cfebbfc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ packages =
py_modules = py
install_requires =
iniconfig
more-itertools
packaging
pluggy>=0.12,<2.0
colorama;sys_platform=="win32"
Expand Down
16 changes: 5 additions & 11 deletions src/_pytest/mark/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
from typing import TypeVar
from typing import Union

from more_itertools import always_iterable
from more_itertools import flatten

from .._code import getfslineno
from ..compat import ascii_escaped
from ..compat import NOTSET
Expand Down Expand Up @@ -375,18 +378,9 @@ def get_unpacked_marks(
mark_lists = [obj.__dict__.get("pytestmark", [])]
else:
mark_lists = [x.__dict__.get("pytestmark", []) for x in obj.__mro__]
mark_list = []
for item in mark_lists:
if isinstance(item, list):
mark_list.extend(item)
else:
mark_list.append(item)
else:
mark_attribute = getattr(obj, "pytestmark", [])
if isinstance(mark_attribute, list):
mark_list = mark_attribute
else:
mark_list = [mark_attribute]
mark_lists = [getattr(obj, "pytestmark", [])]
mark_list = flatten(map(always_iterable, mark_lists))
return list(normalize_mark_list(mark_list))


Expand Down

0 comments on commit cfebbfc

Please sign in to comment.