add an example for lazy "per-directory" setup.
--HG-- branch : trunk
This commit is contained in:
parent
46be553c25
commit
44abdc9391
|
@ -0,0 +1,22 @@
|
|||
|
||||
class ConftestPlugin:
|
||||
def pytest_configure(self, config):
|
||||
self._setup = None
|
||||
|
||||
def pytest_funcarg__setup(self, request):
|
||||
if self._setup is None:
|
||||
self._setup = LazySetup()
|
||||
return self._setup
|
||||
|
||||
def pytest_unconfigure(self, config):
|
||||
if self._setup is not None:
|
||||
self._setup.finalize()
|
||||
|
||||
class LazySetup:
|
||||
def __init__(self):
|
||||
import time
|
||||
time.sleep(5)
|
||||
self.timecostly = 1
|
||||
|
||||
def finalize(self):
|
||||
del self.timecostly
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
def test_something(setup):
|
||||
assert setup.timecostly == 1
|
||||
|
||||
def test_something_more(setup):
|
||||
assert setup.timecostly == 1
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
def test_quick():
|
||||
pass
|
Loading…
Reference in New Issue