parent
763e075bab
commit
65a04bc3be
|
@ -81,7 +81,7 @@ If you run this with ``py.test test_simpleprovider.py`` you see something like t
|
||||||
This means that the test function got executed and the assertion failed.
|
This means that the test function got executed and the assertion failed.
|
||||||
Here is how py.test comes to execute this test function:
|
Here is how py.test comes to execute this test function:
|
||||||
|
|
||||||
1. py.test discovers the ``test_function`` because of the ``test_prefix``.
|
1. py.test discovers the ``test_function`` because of the ``test_`` prefix.
|
||||||
The test function needs a function argument named ``myfuncarg``.
|
The test function needs a function argument named ``myfuncarg``.
|
||||||
A matching provider function is discovered by looking for the special
|
A matching provider function is discovered by looking for the special
|
||||||
name ``pytest_funcarg__myfuncarg``.
|
name ``pytest_funcarg__myfuncarg``.
|
||||||
|
@ -312,15 +312,13 @@ following code into a local ``conftest.py``:
|
||||||
|
|
||||||
class ConftestPlugin:
|
class ConftestPlugin:
|
||||||
def pytest_funcarg__mysetup(self, request):
|
def pytest_funcarg__mysetup(self, request):
|
||||||
return MySetup(request)
|
return MySetup()
|
||||||
|
|
||||||
class MySetup:
|
class MySetup:
|
||||||
def __init__(self, request):
|
|
||||||
self.config = request.config
|
|
||||||
def myapp(self):
|
def myapp(self):
|
||||||
return MyApp()
|
return MyApp()
|
||||||
|
|
||||||
To run the example we put a pseudo MyApp object into ``myapp.py``:
|
To run the example we represent our application by putting a pseudo MyApp object into ``myapp.py``:
|
||||||
|
|
||||||
.. sourcecode:: python
|
.. sourcecode:: python
|
||||||
|
|
||||||
|
@ -412,7 +410,7 @@ Now any test function can use the ``mysetup.getsshconnection()`` method like thi
|
||||||
conn = mysetup.getsshconnection()
|
conn = mysetup.getsshconnection()
|
||||||
# work with conn
|
# work with conn
|
||||||
|
|
||||||
Running this without specifying a command line option will result in a skipped test_function:
|
Running ``py.test test_ssh.py`` without specifying a command line option will result in a skipped test_function:
|
||||||
|
|
||||||
.. sourcecode:: python
|
.. sourcecode:: python
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,8 @@ from myapp import MyApp
|
||||||
|
|
||||||
class ConftestPlugin:
|
class ConftestPlugin:
|
||||||
def pytest_funcarg__mysetup(self, request):
|
def pytest_funcarg__mysetup(self, request):
|
||||||
return MySetup(request)
|
return MySetup()
|
||||||
|
|
||||||
class MySetup:
|
class MySetup:
|
||||||
def __init__(self, request):
|
|
||||||
self.config = request.config
|
|
||||||
def myapp(self):
|
def myapp(self):
|
||||||
return MyApp()
|
return MyApp()
|
||||||
|
|
Loading…
Reference in New Issue