From 18fbe2fd9e6a888ba93d3faf348db6b84d95f5fd Mon Sep 17 00:00:00 2001 From: Victor Date: Fri, 25 May 2018 11:45:11 +0200 Subject: [PATCH 1/2] Add test for hiding self parameter. --- .../steps/parameters/step_parameters_test.py | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/allure-pytest/test/steps/parameters/step_parameters_test.py b/allure-pytest/test/steps/parameters/step_parameters_test.py index c9bbb1de..00e9f9cc 100644 --- a/allure-pytest/test/steps/parameters/step_parameters_test.py +++ b/allure-pytest/test/steps/parameters/step_parameters_test.py @@ -60,4 +60,27 @@ def test_text_type_parameters(): ... ) ... ) """ - step_with_parameters(u'первый', kwarg_parameter='второй') \ No newline at end of file + 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') From 74b26433a673f524a9b0292f984cef82763ba73a Mon Sep 17 00:00:00 2001 From: Victor Date: Fri, 25 May 2018 11:53:06 +0200 Subject: [PATCH 2/2] Add test for hiding self parameter. Fixes #222 --- allure-python-commons-test/src/result.py | 10 +++++++++- allure-python-commons/src/utils.py | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/allure-python-commons-test/src/result.py b/allure-python-commons-test/src/result.py index d6feb3d3..9e984a45 100644 --- a/allure-python-commons-test/src/result.py +++ b/allure-python-commons-test/src/result.py @@ -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 @@ -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( diff --git a/allure-python-commons/src/utils.py b/allure-python-commons/src/utils.py index 72457501..3d3d5711 100644 --- a/allure-python-commons/src/utils.py +++ b/allure-python-commons/src/utils.py @@ -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