1. JeffDonner
  2. pytest-fix-issue-50

Commits

JeffDonner  committed 3181d5a

cleanup

  • Participants
  • Parent commits bee52a5
  • Branches default

Comments (0)

Files changed (1)

File _pytest/mark.py

View file
 
 
 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
+            order:
+       -m dev -m -prod
+          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.
+       """
+
     if not filterlist:
         return
 
     remaining = set([])
     deselected = set([])
-    # -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 = ' ' in and_expr
             if is_compound:
                 # 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"
                     remaining.add(i)
                     pass
                 else:
                     deselected.add(i)
-            # We will
+            # Single
             else:
                 mark = and_expr
-                # single item; because the overall meaning is 'or', we
-                # do not remove earlier items that have been added to
-                # <remainder>.
                 is_neg = mark[:1] == '-'
                 if is_neg:
                     bare_mark = mark[1:]
                         remaining.add(i)
                         deselected.discard(i)
 
-        # 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).
         if i not in remaining:
             deselected.add(i)
 
     # didn't have any mismatches - it's ok by us
     return True
 
-def single_says_skip(item_marks, mark):
-    if not single_expr: return False
-
-    is_neg = mark[:1] == '-'
-    if is_neg:
-        mark = mark[1:]
-    return is_neg == mark_present(mark, item_marks)
-
-# blatantly lifted from _pytest.mark.py but checks now for whether it is
-# a MarkInfo object
+# blatantly lifted from _pytest.mark.py but checks now for whether
+# it is a MarkInfo object
 def get_marks(node):
     marks = {}
     while node is not None:
         node = node.parent
     return marks
 
-
 # blatantly lifted from _pytest.mark.py
 # &&& whether there's any intersection between flattened(item_markwords)
 #   and mark.split('.')
         else:
             return False
     return True
-
-
-class MarkFiltration(object):
-    pass