Skip to content

Commit be35a6a

Browse files
committed
Skipping by capability/feature
This change provide a way to skip one or more tests using features names to make it easier to understand why the test is being skipped, specially in the case it is testing new features by avoid the if `list of language` approach. It does not replace the skipped lists implemented for each driver testkit-backend since the skip reason could be different. The usage of the RunTest message to fetch capabilities was done to keep a simple and backwards compatible way to use the fetch this information.
1 parent e13c397 commit be35a6a

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

nutkit/protocol/responses.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323

2424
class RunTest:
2525
""" Response to StartTest indicating that the test can be started"""
26-
pass
26+
27+
def __init__(self, capabilities=None):
28+
if capabilities is None:
29+
capabilities = []
30+
self.capabilities = capabilities
2731

2832

2933
class SkipTest:

tests/shared.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ def new_backend():
3030
return Backend(host, port)
3131

3232

33+
def driver_feature(capability):
34+
def get_valid_test_case(*args, **kwargs):
35+
if not args or not isinstance(args[0], TestkitTestCase):
36+
raise Exception('Should only decorate TestkitTestCase methods')
37+
return args[0]
38+
39+
def driver_feature_decorator(func):
40+
def wrapper(*args, **kwargs):
41+
test_case = get_valid_test_case(*args, **kwargs)
42+
if (capability not in test_case._driver_capabilities):
43+
test_case.skipTest("Needs support for %s" % capability)
44+
return func(*args, **kwargs)
45+
return wrapper
46+
return driver_feature_decorator
47+
48+
3349
def get_driver_name():
3450
return os.environ['TEST_DRIVER_NAME']
3551

@@ -59,6 +75,7 @@ def setUp(self):
5975
raise Exception("Should be SkipTest or RunTest, "
6076
"received {}: {}".format(type(response),
6177
response))
78+
self._driver_capabilities = response.capabilities
6279

6380
def script_path(self, *path):
6481
base_path = os.path.dirname(inspect.getfile(self.__class__))

tests/stub/authorization.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from tests.shared import (
44
get_driver_name,
55
TestkitTestCase,
6+
driver_feature
67
)
78
from tests.stub.shared import StubServer
89

@@ -698,6 +699,7 @@ def read_return_1_failure_return_2_succeed_script(self):
698699
+}
699700
"""
700701

702+
@driver_feature('AutorizationExpiredTreament')
701703
def test_should_drop_connection_after_AuthorizationExpired(self):
702704
self._server.start(
703705
script=self.read_return_1_failure_return_2_succeed_script()
@@ -732,6 +734,7 @@ def test_should_drop_connection_after_AuthorizationExpired(self):
732734

733735
driver.close()
734736

737+
@driver_feature('AutorizationExpiredTreament')
735738
def test_should_be_able_to_use_current_sessions_after_AuthorizationExpired(self):
736739
self._server.start(
737740
script=self.read_return_1_failure_return_2_succeed_script()

0 commit comments

Comments
 (0)