-
Notifications
You must be signed in to change notification settings - Fork 44
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
Skip tests affected by bug 695 #49
Conversation
At this point, you have to manually configure Pulp Smash and tell it which version of Pulp you're targeting, and there's also no integration with the bug tracker at pulp.plan.io. But it's a start, and it demonstrates how to use the new "version" attribute on the |
This looks good. I do have one suggestion. Can a decorator be introduced? It would be like this:
Or maybe this:
|
Yes, we can do that. The problem with using decorators here is that they are evaluated when defined, but we don't want to be instantiating It's definitely doable. It's done in Robottelo, and @elyezer in particular has expertise with writing them. But I'm nervous about adopting something like that right away. This approach is not as concise, but it serves the lowest common denominator. My spidey senses tell me to do other things (like integrate with pulp.plan.io and expand the test suite) first. |
By the way, I do like the two-argument form you've given. I like the idea of requiring that users provide a bug URL in order to skip a test. It might also allow for some nice analytics down the line when we get good TCMS integration in place. |
The complexity of introducing a decorator versus integrating with a web server are significantly different. Regarding making a decorator I could write one up and post it here if that is helpful. I really think this is an idiom we want to include from the start. I'm not concerned if What do you think? Also if we want to be sure it's a bug (which could be good to require) we could use it like:
|
|
What I'm much more worried about is that |
But hey, if we can get a well-engineered decorator now - that'd be great. Please do put something together if you have a few minutes. 😄 |
@bmbouter Actually, is there even any need to state the version at which a bug is fixed? We could just do something like this: @skip_if_open(695)
def test_foo(self):
pass And at run-time, we can grab a |
This would require integration with Redmine at this time. It would be advantageous to hold off on doing that integration till later. |
Why so? Integration is extremely easy. |
Even though it is easy, it is still another step that we have to take before we can start skipping tests. |
We can skip tests right now! |
Basically, if we're going to go above and beyond serving the lowest common denominator, let's make sure what we come up with is orthogonal to what we already have. |
Here is a simple decorator for it. Personally I think introducing the decorator is good to do now. More than redmine integration, I think all the core tools bugs need to be done. I like the integration, but I don't think it's blocking test writing. I'm still blocked on #31 def require(func, version_string):
def new_func(self, *args, **kwargs):
if self.cfg.version < Version(version_string):
self.skipTest('Test requires version %s' % version_string)
else:
return func(self, *args, **kwargs)
return new_func |
@bmbouter Concise. I like it. |
I'll add that as a second commit in this PR and ask for a re-review then. This may come in handy later: #!/usr/bin/env python
"""Fetch the target release of a bug.
This can fail in at least two obvious cases:
* There is an error while communicating with the server. (e.g. cannot be
reached)
* There is no "target release" set on the bug.
In either case, an appropriately cautious response is to assume that the bug is
applicable and open.
"""
from __future__ import print_function
import requests
response = requests.get('https://pulp.plan.io/issues/695.json')
response.raise_for_status()
target_releases = [
custom_field for custom_field in response.json()['issue']['custom_fields']
if custom_field['id'] == 4 # 'name': 'Target Release'
]
assert len(target_releases) == 1
print(target_releases[0]['value']) |
Fix #29, "Add mechanism to select tests based on Pulp version": > Some tests are only applicable to a particular Python version. Let's add some > mechanism that allows users to run only tests which apply to a particular Pulp > version or a range of Pulp versions. A new "version" attribute was recently added to `pulp_smash.config.ServerConfig`. Build on top of that work by adding a new decorator, `pulp_smash.utils.requires`. As its docstring states: This decorator concisely encapsulates a common pattern for skipping tests. It can be used like so: >>> from pulp_smash.config import get_config >>> from pulp_smash.utils import require >>> from unittest import TestCase >>> class MyTestCase(TestCase): ... ... @classmethod ... def setUpClass(cls): ... cls.cfg = get_config() ... ... @require('2.7') # References `self.cfg` ... def test_foo(self): ... pass # Add a test for Pulp 2.7+ here. Notice that ``cls.cfg`` is assigned to. This is a **requirement**. Of special note is that the decorator will throw an exception if an invalid version is passed. For example, this will throw an exception: @require('2.7.foobar') def test_foo(self): pass Many thanks to @bmbouter for help with this change.
Skip test `CreateSuccessTestCase.test_location_header` in module `pulp_smash.tests.platform.api_v2.test_repository` if Pulp 2.6 or older is targeted. Test suite results do not change when run against Pulp 2.7 (and the Pulp Smash settings file is configured appropriately). This fixes two failing tests when run against Pulp 2.6. Test results before this change: $ PULP_SMASH_CONFIG_FILE=pulp-2.6.json python -m unittest2 \ > pulp_smash.tests.platform.api_v2.test_repository … Ran 11 tests in 1.947s FAILED (failures=8) Test results with this change applied: $ PULP_SMASH_CONFIG_FILE=pulp-2.6.json python -m unittest2 \ > pulp_smash.tests.platform.api_v2.test_repository … Ran 11 tests in 1.961s FAILED (failures=6, skipped=1)
Decorator usage boils down to this: @require('2.7') # https://pulp.plan.io/issues/695
def test_foo(self):
pass I implemented the decorator so as to fail if an invalid version string is passed. This will throw an exception: @require('2.7.foobar') # https://pulp.plan.io/issues/695
def test_foo(self):
pass |
@Ichimonji10 nice! I really like it. |
I've manually verified this change one more time. When the test suite is run
When the test suite is run against Pulp 2.7, nothing changes:
Merging changes now. |
Add a decorator for skipping tests,
pulp_smash.utils.require
. Use it to skip a test that is known to fail under Pulp 2.6 and older. See individual commit messages for more details.