Skip to content

Commit 1c89ee2

Browse files
committed
some more docstrings
1 parent b8a2a5c commit 1c89ee2

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

pytest_twisted.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,18 @@ def decorator_apply(dec, func):
120120

121121

122122
def inlineCallbacks(f):
123+
"""
124+
Mark as inline callbacks test for pytest-twisted processing and apply
125+
@inlineCallbacks.
126+
"""
123127
decorated = decorator_apply(defer.inlineCallbacks, f)
124128
_set_mark(o=decorated, mark='inline_callbacks_test')
125129

126130
return decorated
127131

128132

129133
def ensureDeferred(f):
134+
"""Mark as async test for pytest-twisted processing."""
130135
_set_mark(o=f, mark='async_test')
131136

132137
return f
@@ -151,10 +156,12 @@ def stop_twisted_greenlet():
151156

152157

153158
def _get_mark(o, default=None):
159+
"""Get the pytest-twisted test or fixture mark."""
154160
return getattr(o, _mark_attribute_name, default)
155161

156162

157163
def _set_mark(o, mark):
164+
"""Set the pytest-twisted test or fixture mark."""
158165
setattr(o, _mark_attribute_name, mark)
159166

160167

@@ -167,8 +174,15 @@ def fixture(*args, **kwargs):
167174
scope = kwargs.get('scope', 'function')
168175

169176
if scope not in ['function', 'module']:
170-
# TODO: add test for session scope (and that's it, right?)
171-
# then remove this and update docs
177+
# TODO: handle...
178+
# - class
179+
# - package
180+
# - session
181+
# - dynamic
182+
#
183+
# https://docs.pytest.org/en/latest/reference.html#pytest-fixture-api
184+
# then remove this and update docs, or maybe keep it around
185+
# in case new options come in without support?
172186
raise AsyncFixtureUnsupportedScopeError.from_scope(scope=scope)
173187

174188
def decorator(f):
@@ -188,22 +202,22 @@ def decorator(f):
188202

189203

190204
def pytest_fixture_setup(fixturedef, request):
191-
"""Interface pytest to async setup for async and async yield fixtures."""
205+
"""Interface pytest to async for async and async yield fixtures."""
192206
# TODO: what about _adding_ inlineCallbacks fixture support?
193207
maybe_mark = _get_mark(fixturedef.func)
194208
if maybe_mark is None:
195209
return None
196210

197211
mark = maybe_mark
198212

199-
run_inline_callbacks(_async_pytest_fixture_setup, fixturedef, request, mark)
213+
_run_inline_callbacks(_async_pytest_fixture_setup, fixturedef, request, mark)
200214

201215
return not None
202216

203217

204218
@defer.inlineCallbacks
205219
def _async_pytest_fixture_setup(fixturedef, request, mark):
206-
"""Setup async and async yield fixtures."""
220+
"""Setup an async or async yield fixture."""
207221
fixture_function = fixturedef.func
208222

209223
kwargs = {
@@ -266,12 +280,8 @@ def tear_it_down(deferred):
266280
)
267281

268282

269-
# TODO: https://docs.pytest.org/en/latest/reference.html#_pytest.hookspec.pytest_runtest_protocol
270-
# claims it should also take a nextItem but that triggers a direct error
271-
272-
273-
def run_inline_callbacks(f, *args):
274-
"""Interface into Twisted greenlet to run and wait for deferred."""
283+
def _run_inline_callbacks(f, *args):
284+
"""Interface into Twisted greenlet to run and wait for a deferred."""
275285
if _instances.gr_twisted is not None:
276286
if _instances.gr_twisted.dead:
277287
raise RuntimeError("twisted reactor has stopped")
@@ -295,13 +305,15 @@ def pytest_runtest_teardown(item):
295305

296306
while len(_tracking.to_be_torn_down) > 0:
297307
deferred = _tracking.to_be_torn_down.pop(0)
298-
run_inline_callbacks(tear_it_down, deferred)
308+
_run_inline_callbacks(tear_it_down, deferred)
299309

300310

301311
def pytest_pyfunc_call(pyfuncitem):
302312
"""Interface to async test call handler."""
303313
# TODO: only handle 'our' tests? what is the point of handling others?
304-
run_inline_callbacks(_async_pytest_pyfunc_call, pyfuncitem)
314+
# well, because our interface allowed people to return deferreds
315+
# from arbitrary tests so we kinda have to keep this up for now
316+
_run_inline_callbacks(_async_pytest_pyfunc_call, pyfuncitem)
305317
return not None
306318

307319

@@ -328,6 +340,7 @@ def _async_pytest_pyfunc_call(pyfuncitem):
328340

329341
@pytest.fixture(scope="session", autouse=True)
330342
def twisted_greenlet():
343+
"""Provide the twisted greenlet in fixture form."""
331344
return _instances.gr_twisted
332345

333346

0 commit comments

Comments
 (0)