Skip to content

Commit

Permalink
Merge pull request #244 from zaneb/no-class-skip
Browse files Browse the repository at this point in the history
Fix issues with skipping tests when unconfigured
  • Loading branch information
cdent committed Apr 20, 2018
2 parents 26e96aa + 8354d54 commit 29d8364
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions gabbi/suitemaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"""

import copy
import functools

from gabbi import case
from gabbi.exception import GabbiFormatError
Expand Down Expand Up @@ -85,6 +86,14 @@ def make_one_test(self, test_dict, prior_test):
else:
history = {}

test_method_name = 'test_request'
test_method = getattr(case.HTTPTestCase, test_method_name)

@case.testcase.skipIf(self.host == '', 'No host configured')
@functools.wraps(test_method)
def do_test(*args, **kwargs):
return test_method(*args, **kwargs)

# Use metaclasses to build a class of the necessary type
# and name with relevant arguments.
klass = TestBuilder(test_name, (case.HTTPTestCase,),
Expand All @@ -101,15 +110,14 @@ def make_one_test(self, test_dict, prior_test):
'prefix': self.prefix,
'prior': prior_test,
'history': history,
test_method_name: do_test,
})
# We've been asked to, make this test class think it comes
# from a different module.
if self.test_loader_name:
klass.__module__ = self.test_loader_name
check_host = case.testcase.skipIf(not self.host,
'No host configured')

tests = self.loader.loadTestsFromTestCase(check_host(klass))
tests = self.loader.loadTestsFromTestCase(klass)
history[test['name']] = tests._tests[0]
# Return the first (and only) test in the klass.
return tests._tests[0]
Expand Down

0 comments on commit 29d8364

Please sign in to comment.