Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature hide self parameter #235

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion allure-pytest/test/steps/parameters/step_parameters_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,27 @@ def test_text_type_parameters():
... )
... )
"""
step_with_parameters(u'первый', kwarg_parameter='второй')
step_with_parameters(u'первый', kwarg_parameter='второй')


class StepClass(object):

@allure.step('First step')
def first_step_method(self, arg1):
pass


def test_self_not_in_parameters():
"""
>>> from allure_commons.utils import represent
>>> allure_report = getfixture('allure_report_with_params')('-k test_self_not_in_parameters')
>>> assert_that(allure_report,
... has_test_case('test_self_not_in_parameters',
... has_step('First step',
... has_parameter('arg1', represent('argument one')),
... doesnt_have_parameter('self'),
... )
... )
... )
"""
StepClass().first_step_method('argument one')
10 changes: 9 additions & 1 deletion allure-python-commons-test/src/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

"""

from hamcrest import all_of, anything
from hamcrest import all_of, anything, not_
from hamcrest import equal_to, not_none
from hamcrest import has_entry, has_item
from hamcrest import contains_string, starts_with
Expand Down Expand Up @@ -100,6 +100,14 @@ def has_parameter(name, value):
))


def doesnt_have_parameter(name):
return has_entry('parameters',
not_(
has_item(
has_entry('name', equal_to(name)),
)))


def has_link(url, link_type=None, name=None):
return has_entry('links',
has_item(
Expand Down
8 changes: 8 additions & 0 deletions allure-python-commons/src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,15 @@ def represent(item):
def func_parameters(func, *a, **kw):
bowels = inspect.getargspec(func) if sys.version_info.major < 3 else inspect.getfullargspec(func)
args_dict = dict(zip(bowels.args, map(represent, a)))
try:
del args_dict["self"]
except KeyError:
pass
kwargs_dict = dict(zip(kw, list(map(lambda i: represent(kw[i]), kw))))
try:
del kwargs_dict["self"]
except KeyError:
pass
kwarg_defaults = dict(zip(reversed(bowels.args), reversed(list(map(represent, bowels.defaults or ())))))
kwarg_defaults.update(kwargs_dict)
return args_dict, kwarg_defaults
Expand Down