| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6912b3c commit c37b8b0
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -136,7 +136,8 @@ def pytest_fixture_setup(self, fixturedef, request): | |||
| 136 | 136 | ||
| 137 | 137 | finalizers = getattr(fixturedef, '_finalizers', []) | |
| 138 | 138 | for index, finalizer in enumerate(finalizers): | |
| 139 | - name = '{fixture}::{finalizer}'.format(fixture=fixturedef.argname, finalizer=finalizer.__name__) | ||
| 139 | + name = '{fixture}::{finalizer}'.format(fixture=fixturedef.argname, | ||
| 140 | + finalizer=getattr(finalizer, "__name__", index)) | ||
| 140 | 141 | finalizers[index] = allure_commons.fixture(finalizer, parent_uuid=container_uuid, name=name) | |
| 141 | 142 | ||
| 142 | 143 | @pytest.hookimpl(hookwrapper=True) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,18 @@ | |||
| 1 | + import pytest | ||
| 2 | + | ||
| 3 | + | ||
| 4 | + @pytest.fixture | ||
| 5 | + def fixture_one(): | ||
| 6 | + yield | ||
| 7 | + | ||
| 8 | + | ||
| 9 | + def test_yield_fixture(fixture_one): | ||
| 10 | + """ | ||
| 11 | + >>> allure_report = getfixture('allure_report') | ||
| 12 | + >>> assert_that(allure_report, | ||
| 13 | + ... has_test_case('test_yield_fixture', | ||
| 14 | + ... with_status('passed') | ||
| 15 | + ... ) | ||
| 16 | + ... ) | ||
| 17 | + """ | ||
| 18 | + pass | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,6 +12,53 @@ | |||
| 12 | 12 | import threading | |
| 13 | 13 | import traceback | |
| 14 | 14 | import collections | |
| 15 | + from functools import partial | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + def getargspec(func): | ||
| 19 | + """ | ||
| 20 | + Used because getargspec for python 2.7 does not accept functools.partial | ||
| 21 | + which is the type for pytest fixtures. | ||
| 22 | + | ||
| 23 | + getargspec excerpted from: | ||
| 24 | + | ||
| 25 | + sphinx.util.inspect | ||
| 26 | + ~~~~~~~~~~~~~~~~~~~ | ||
| 27 | + Helpers for inspecting Python modules. | ||
| 28 | + :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. | ||
| 29 | + :license: BSD, see LICENSE for details. | ||
| 30 | + | ||
| 31 | + Like inspect.getargspec but supports functools.partial as well. | ||
| 32 | + """ | ||
| 33 | + # type: (Any) -> Any | ||
| 34 | + if inspect.ismethod(func): | ||
| 35 | + func = func.__func__ | ||
| 36 | + parts = 0, () # type: Tuple[int, Tuple[unicode, ...]] | ||
| 37 | + if type(func) is partial: | ||
| 38 | + keywords = func.keywords | ||
| 39 | + if keywords is None: | ||
| 40 | + keywords = {} | ||
| 41 | + parts = len(func.args), keywords.keys() | ||
| 42 | + func = func.func | ||
| 43 | + if not inspect.isfunction(func): | ||
| 44 | + raise TypeError('%r is not a Python function' % func) | ||
| 45 | + args, varargs, varkw = inspect.getargs(func.__code__) | ||
| 46 | + func_defaults = func.__defaults__ | ||
| 47 | + if func_defaults is None: | ||
| 48 | + func_defaults = [] | ||
| 49 | + else: | ||
| 50 | + func_defaults = list(func_defaults) | ||
| 51 | + if parts[0]: | ||
| 52 | + args = args[parts[0]:] | ||
| 53 | + if parts[1]: | ||
| 54 | + for arg in parts[1]: | ||
| 55 | + i = args.index(arg) - len(args) # type: ignore | ||
| 56 | + del args[i] | ||
| 57 | + try: | ||
| 58 | + del func_defaults[i] | ||
| 59 | + except IndexError: | ||
| 60 | + pass | ||
| 61 | + return inspect.ArgSpec(args, varargs, varkw, func_defaults) # type: ignore | ||
| 15 | 62 | ||
| 16 | 63 | ||
| 17 | 64 | if six.PY3: | |
@@ -252,7 +299,7 @@ def func_parameters(func, *args, **kwargs): | |||
| 252 | 299 | ||
| 253 | 300 | """ | |
| 254 | 301 | parameters = {} | |
| 255 | - arg_spec = inspect.getargspec(func) if six.PY2 else inspect.getfullargspec(func) | ||
| 302 | + arg_spec = getargspec(func) if six.PY2 else inspect.getfullargspec(func) | ||
| 256 | 303 | arg_order = list(arg_spec.args) | |
| 257 | 304 | args_dict = dict(zip(arg_spec.args, args)) | |
| 258 | 305 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments