def filter_by_marks(items, un_items, filterlist):
- """We modify <items> in-place."""
+ """Modifies <items> and <un_items> in-place.
+ -m -prod -m dev => filterlist == ['-prod', 'dev']
+ -- which means, give me everything that's not prod, and,
+ everything marked dev (which is redundant). The reverse
+ will add everything marked dev, then exclude everything
+ marked prod - later pieces of the filter take precedence over
+ earlier ones (in the order they appear in 'filterlist')
+ -m "-prod dev" => filterlist == ['-prod dev']
+ -- means, give me everything that's both 'not prod, and dev'
+ Note that and-shaped criteria (eg -m "foo bar -baz") will
+ never remove an item selected by an earlier part of the filter.
- # -m -prod -m dev => filterlist == ['-prod', 'dev']
- # -- which means, give me everything that's not prod, and, everything that's dev
- # -m "-prod dev" => filterlist == ['-prod dev']
- # -- which means, give me everything that's both 'not prod, and dev'
for i, item in enumerate(items):
item_marks = get_marks(item)
for and_expr in filterlist:
- is_compound = and_expr
.find(' ') >= 0
+ is_compound = and_expr
# In this design, 'and' expressions can only ever add to items
if and_expr_satisfied(item_marks, and_expr):
- print "keeping", "and_expr:", and_expr, "item marks:", item_marks
# keep (or restore after being previously skipped;
# eg prod in "-prod dev prod"
- # single item; because the overall meaning is 'or', we
- # do not remove earlier items that have been added to
- # given that the top-level filters are 'or', finally, if none
- # has selected them, we must remove the item (given that, by being
- # here, we know that /some/ filter criteria has/have been given).
+ # Given that the top-level filters are 'or'ed, finally, if no
+ # filter has selected the item, we must remove the it (given
+ # that, by being here, we know that /some/ filter criteria
+ # has/have been given).
# didn't have any mismatches - it's ok by us
-def single_says_skip(item_marks, mark):
- if not single_expr: return False
- is_neg = mark[:1] == '-'
- return is_neg == mark_present(mark, item_marks)
-# blatantly lifted from _pytest.mark.py but checks now for whether it is
+# blatantly lifted from _pytest.mark.py but checks now for whether
+# it is a MarkInfo object
# blatantly lifted from _pytest.mark.py
# &&& whether there's any intersection between flattened(item_markwords)