1. Ronny Pfannschmidt
  2. pytest-patches

Commits

Ronny Pfannschmidt  committed 51211e9

initial

  • Participants
  • Branches default

Comments (0)

Files changed (3)

File fnmatch-python-test-names

View file
+# HG changeset patch
+# Parent b8f6abd0c27fdd6b13bd67d072d390b10d682464
+diff --git a/_pytest/python.py b/_pytest/python.py
+--- a/_pytest/python.py
++++ b/_pytest/python.py
+@@ -3,6 +3,7 @@ import py
+ import inspect
+ import sys
+ import pytest
++import fnmatch
+ from py._code.code import TerminalRepr
+ 
+ import _pytest
+@@ -163,11 +164,15 @@ class PyCollectorMixin(PyobjMixin, pytes
+         for prefix in self.config.getini("python_functions"):
+             if name.startswith(prefix):
+                 return True
++            if not prefix.isalnum() and fnmatch.fnmatchcase(name, prefix):
++                return True
+ 
+     def classnamefilter(self, name):
+         for prefix in self.config.getini("python_classes"):
+             if name.startswith(prefix):
+                 return True
++            if not prefix.isalnum() and fnmatch.fnmatchcase(name, prefix):
++                return True
+ 
+     def collect(self):
+         # NB. we avoid random getattrs and peek in the __dict__ instead
+diff --git a/testing/test_python.py b/testing/test_python.py
+--- a/testing/test_python.py
++++ b/testing/test_python.py
+@@ -1301,8 +1301,8 @@ def test_customized_python_discovery(tes
+     testdir.makeini("""
+         [pytest]
+         python_files=check_*.py
+-        python_classes=Check
+-        python_functions=check
++        python_classes=Check Describe*
++        python_functions=check *_should_*
+     """)
+     p = testdir.makepyfile("""
+         def check_simple():
+@@ -1310,6 +1310,9 @@ def test_customized_python_discovery(tes
+         class CheckMyApp:
+             def check_meth(self):
+                 pass
++        class DescribeFun:
++            def this_should_work(self):
++                pass
+     """)
+     p2 = p.new(basename=p.basename.replace("test", "check"))
+     p.move(p2)
+@@ -1319,12 +1322,14 @@ def test_customized_python_discovery(tes
+         "*check_simple*",
+         "*CheckMyApp*",
+         "*check_meth*",
++        "*DescribeFun*",
++        "*this_should_work*",
+     ])
+     
+     result = testdir.runpytest()
+     assert result.ret == 0
+     result.stdout.fnmatch_lines([
+-        "*2 passed*",
++        "*3 passed*",
+     ])
+ 
+ def test_collector_attributes(testdir):

File reconfigure-funcargs

View file
+# HG changeset patch
+# Parent 2ca334d2f7015e5a9feb8a28982770509fefaf10
+introduce the pytest_reconfigure_funcargs(request) hook
+
+diff --git a/_pytest/hookspec.py b/_pytest/hookspec.py
+--- a/_pytest/hookspec.py
++++ b/_pytest/hookspec.py
+@@ -115,6 +115,9 @@ pytest_pyfunc_call.firstresult = True
+ def pytest_generate_tests(metafunc):
+     """ generate (multiple) parametrized calls to a test function."""
+ 
++def pytest_reconfigure_funcargs(request):
++    """ reconfigure funcargs after fillfuncatgs but before the call."""
++
+ # -------------------------------------------------------------------------
+ # generic runtest related hooks
+ # -------------------------------------------------------------------------
+diff --git a/_pytest/python.py b/_pytest/python.py
+--- a/_pytest/python.py
++++ b/_pytest/python.py
+@@ -629,6 +629,7 @@ class FuncargRequest:
+         for argname in argnames:
+             if argname not in self._pyfuncitem.funcargs:
+                 self._pyfuncitem.funcargs[argname] = self.getfuncargvalue(argname)
++        self.config.hook.pytest_reconfigure_funcargs.pcall(self._plugins, request=self)
+ 
+ 
+     def applymarker(self, marker):
+diff --git a/doc/funcargs.txt b/doc/funcargs.txt
+--- a/doc/funcargs.txt
++++ b/doc/funcargs.txt
+@@ -115,6 +115,9 @@ think of as "resources").
+ .. _`funcarg factory`:
+ .. _factory:
+ 
++
++
++
+ The funcarg **request** object
+ =============================================
+ 
+@@ -140,6 +143,17 @@ factory and provides access to test conf
+ .. _`parametrizing-tests`:
+ .. _`parametrized test functions`:
+ 
++
++Reconfiguring funcargs in a test's setup
++========================================
++
++Sometimes there is need to do additional funcarg setup steps
++which are outside of the normal setup.
++For that reason the ``pytest_reconfigure_funcargs(request)`` hook
++is called after all required funcargs for a test function are created.
++It is supposed to instanciate additional funcargs or reconfigure already instanciated funcargs.
++It cannot replace the actual objects as created by the ``pytest_funcarg__*`` hooks.
++
+ Parametrizing multiple calls to a test function
+ ===========================================================
+ 
+diff --git a/testing/test_python.py b/testing/test_python.py
+--- a/testing/test_python.py
++++ b/testing/test_python.py
+@@ -606,6 +606,22 @@ class TestFillFuncArgs:
+         fillfuncargs(item)
+         assert len(item.funcargs) == 1
+ 
++    def test_reconfigure_hook(self, testdir):
++        item = testdir.getitem("def test_func(some, other=20): pass")
++        class Provider:
++            def pytest_funcarg__some(self, request):
++                return []
++            def pytest_reconfigure_funcargs(self, request):
++                request.getfuncargvalue('some').append(1)
++        item.config.pluginmanager.register(Provider())
++        if hasattr(item, '_args'):
++            del item._args
++        from _pytest.python import fillfuncargs
++        fillfuncargs(item)
++        assert len(item.funcargs) == 1
++        assert item.funcargs['some'] == [1]
++
++
+ class TestRequest:
+     def test_request_attributes(self, testdir):
+         item = testdir.getitem("""

File series

View file
+reconfigure-funcargs
+fnmatch-python-test-names #+test-names