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

Issue #1201 Added improved test_function_new decorator #1238

Merged
merged 1 commit into from May 7, 2018

Conversation

andy-maier
Copy link
Contributor

@andy-maier andy-maier commented Apr 28, 2018

For details, see the commit message.
Ready for review and merge.

@coveralls
Copy link

coveralls commented Apr 28, 2018

Coverage Status

Coverage remained the same at 82.665% when pulling 901c0fe on andy/#1201-improved-testfunc-decorator into 526b3b8 on master.

@andy-maier andy-maier changed the title Issue #1201 Improved the test_function decorator Issue #1201 Added improved test_function_new decorator Apr 28, 2018
@andy-maier andy-maier force-pushed the andy/#1201-improved-testfunc-decorator branch from fa46263 to fa8a455 Compare April 28, 2018 22:54
@andy-maier andy-maier force-pushed the andy/#1201-improved-testfunc-decorator branch from fa8a455 to c5d0fb3 Compare April 28, 2018 23:10
Copy link
Collaborator

@KSchopmeyer KSchopmeyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far I have not used the general code you created but am trying to incorporate it into the test_wbemconnection_mock tests. Until I get that done I will not really be able to comment but in general this is a logical set of commonality for us.

@andy-maier andy-maier force-pushed the andy/#1201-improved-testfunc-decorator branch 2 times, most recently from 42912c2 to b3706d6 Compare May 2, 2018 22:29
@andy-maier
Copy link
Contributor Author

The discussion of pytest issue pytest-dev/pytest#3435 revealed how this can be done. Implemented the suggestion.

@andy-maier andy-maier force-pushed the andy/#1201-improved-testfunc-decorator branch 5 times, most recently from b3df078 to 70b061f Compare May 2, 2018 23:48
@andy-maier andy-maier force-pushed the andy/#1201-improved-testfunc-decorator branch from 70b061f to 077a735 Compare May 3, 2018 00:34
@andy-maier andy-maier force-pushed the andy/#1201-improved-testfunc-decorator branch from 077a735 to 7772282 Compare May 3, 2018 20:46
Copy link
Collaborator

@KSchopmeyer KSchopmeyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I made mistake in one comment about ordering of decorators. Statement was correct but I think I stated the wrong order.
My comments are minor and purely editorial except changing name of the decorator. I don't have better name now but that name will stay with us.

@@ -137,3 +161,146 @@ def test_CIMClass_equal(

ret = None # Debugging hint
return ret


def test_function_new(test_func):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is probably what will be the major test function decorator in the future, shouldn't we call it something else that _new. Expanded, complete, 2. Not sure of name but new is just transitional as a name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We agreed to remove the old function and to name zhe new function simplified_test_function().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DONE


Notes:

* Using this decorator together with the `pytest.mark.parametrize`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about when applying this decorator with param... this decorator must be inserted before the param... decorator

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be inserted after the param, not before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DONE.

# The code to be tested
act_value = obj[key]

# Verify that an exception raised in this function is not mistaken
# to be the expected exception
assert exp_exc_types is None
assert testcase.exp_exc_types is None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment on line above. 'mistaken as the expected exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DONE, plus changed verify to ensure

# The code to be tested
obj[key] = value

# Verify that an exception raised in this function is not mistaken
# to be the expected exception
assert exp_exc_types is None
assert testcase.exp_exc_types is None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DONE

The `pytest_extensions.test_function` decorator was signature-preserving.
This caused the decorated test functions to have unused arguments, and access
to the `kwargs` dict in the test function needed to by key access to the
`kwargs` dict, causing extra code in the test functions.

This change renames the decorator to `simplified_test_function` and improves
the interface of the test functions which now get the testcase tuple as a
named tuple, and the `kwargs` dict of the testcase as expanded keyword
arguments.

Note that the changed decorator needs to explicitly set the `__signature__`
attribute of the test function, because the `signature()` function used by
pytest uses the signature of the unpacked wrapped function.
See also pytest issue #3435.

Increased the minimum versions for development packages: Package "pytest"
from 3.0.7 to 3.3.0 (due to the support for `signature()`) and package
"py" from 1.4.32 to 1.5.1 (because that is the minimum version required by
"pytest").

Signed-off-by: Andreas Maier <maiera@de.ibm.com>
@andy-maier andy-maier force-pushed the andy/#1201-improved-testfunc-decorator branch from 7772282 to 901c0fe Compare May 7, 2018 05:46
@andy-maier
Copy link
Contributor Author

The latest commit addresses all comments

@andy-maier andy-maier merged commit 5788326 into master May 7, 2018
@andy-maier andy-maier deleted the andy/#1201-improved-testfunc-decorator branch May 7, 2018 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants