holger krekel  committed 7bdfd16

add a way to use "-k pep8" to restrict to only run pep8 checks

  • Participants
  • Parent commits 15ef869
  • Branches default
  • Tags 0.5

Comments (0)

Files changed (4)

     py.test --pep8 mysourcedir # or
     py.test --pep8 mysourcedir/
-If you pass the ``--pep8`` option you will see the current list of
-default "ignores", used when invoking the ```` based checking::
+Running PEP8 checks and no other tests
-    pep8
+You can also restrict your tests to only run "pep8" tests and not
+your other tests by typing::
-Per-Project PEP8 checking configuration
+    py.test --pep8 -k pep8
-You can configure PEP8-checking options for your project
+This will only run tests that are marked with the "pep8" keyword
+which is added for the pep8 test items added by this plugin.
+Looking at currently active PEP8 options
+Note that in the testing header you will see the current list of default "ignores"::
+    pep8 ignore opts: E202 E221 E222 E241 E301 E302 E401 E501 E701 W293 W391 W601 W602
+For the meaning of these error and warning codes, see the error output
+when running against your files or checkout `
+Configuring PEP8 options per-project
+Lastly, you may configure PEP8-checking options for your project
 by adding an ``pep8options`` entry to your ``pytest.ini``
 or ``setup.cfg`` file like this::
     pep8options = +W293 -E200
-For meanings of Error codes refer to
-and the error message that you get.


     """ indicates an error during pep8 checks. """
 class Pep8Item(pytest.Item, pytest.File):
+    def __init__(self, path, parent):
+        super(Pep8Item, self).__init__(path, parent)
+        self.keywords['pep8'] = True
     def runtest(self):
         call =
         pep8ignores = self.config._pep8ignores


     assert result.ret == 0
+def test_keyword_match(testdir):
+    testdir.makepyfile("""
+        def test_hello():
+            a=[ 1,123]
+            #
+    """)
+    result = testdir.runpytest("--pep8", "-k pep8")
+    result.stdout.fnmatch_lines([
+        "*E201*",
+        "*1 failed*",
+    ])
+    assert 'passed' not in result.stdout.str()
 indexserver =
     default =
     testrun =