-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #184 from pytest-dev/less_return_value
become a full package... and `return` not `defer.returnValue()`
- Loading branch information
Showing
6 changed files
with
104 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[flake8] | ||
ignore = | ||
N802 | ||
|
||
per-file-ignores = | ||
src/pytest_twisted/__init__.py: F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from twisted.internet import defer | ||
|
||
|
||
@defer.inlineCallbacks | ||
def _async_pytest_fixture_setup(fixturedef, request, mark): | ||
"""Setup an async or async yield fixture.""" | ||
from pytest_twisted import ( | ||
UnrecognizedCoroutineMarkError, | ||
_create_async_yield_fixture_finalizer, | ||
) | ||
|
||
fixture_function = fixturedef.func | ||
|
||
kwargs = { | ||
name: request.getfixturevalue(name) | ||
for name in fixturedef.argnames | ||
} | ||
|
||
if mark == 'async_fixture': | ||
arg_value = yield defer.ensureDeferred( | ||
fixture_function(**kwargs) | ||
) | ||
elif mark == 'async_yield_fixture': | ||
coroutine = fixture_function(**kwargs) | ||
|
||
request.addfinalizer( | ||
_create_async_yield_fixture_finalizer(coroutine=coroutine), | ||
) | ||
|
||
arg_value = yield defer.ensureDeferred(coroutine.__anext__()) | ||
else: | ||
raise UnrecognizedCoroutineMarkError.from_mark(mark=mark) | ||
|
||
fixturedef.cached_result = (arg_value, fixturedef.cache_key(request), None) | ||
|
||
return arg_value | ||
|
||
|
||
@defer.inlineCallbacks | ||
def _async_pytest_pyfunc_call(pyfuncitem, f, kwargs): | ||
"""Run test function.""" | ||
from pytest_twisted import _get_mark | ||
|
||
fixture_kwargs = { | ||
name: value | ||
for name, value in pyfuncitem.funcargs.items() | ||
if name in pyfuncitem._fixtureinfo.argnames | ||
} | ||
kwargs.update(fixture_kwargs) | ||
|
||
maybe_mark = _get_mark(f) | ||
if maybe_mark == 'async_test': | ||
result = yield defer.ensureDeferred(f(**kwargs)) | ||
elif maybe_mark == 'inline_callbacks_test': | ||
result = yield f(**kwargs) | ||
else: | ||
# TODO: maybe deprecate this | ||
result = yield f(**kwargs) | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from twisted.internet import defer | ||
|
||
|
||
@defer.inlineCallbacks | ||
def _async_pytest_pyfunc_call(pyfuncitem, f, kwargs): | ||
"""Run test function.""" | ||
from pytest_twisted import _get_mark | ||
|
||
fixture_kwargs = { | ||
name: value | ||
for name, value in pyfuncitem.funcargs.items() | ||
if name in pyfuncitem._fixtureinfo.argnames | ||
} | ||
kwargs.update(fixture_kwargs) | ||
|
||
maybe_mark = _get_mark(f) | ||
if maybe_mark == 'async_test': | ||
result = yield defer.ensureDeferred(f(**kwargs)) | ||
elif maybe_mark == 'inline_callbacks_test': | ||
result = yield f(**kwargs) | ||
else: | ||
# TODO: maybe deprecate this | ||
result = yield f(**kwargs) | ||
|
||
defer.returnValue(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters