Skip to content

Commit

Permalink
Allow a fixture to cause a file to skip all tests
Browse files Browse the repository at this point in the history
If a fixture class raises unittest.case.SkipTest then all the tests
in the YAML file associated with that test will be skipped.
  • Loading branch information
cdent committed Jan 21, 2015
1 parent 35c731b commit 3bb36fa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
6 changes: 6 additions & 0 deletions docs/source/fixtures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ any direct awareness of the fixtures. The fixtures exist, instead, on the
inside of the API being tested. Their most common function is
expected to be the creation of sample data, by whatever means make
sense for the system being tested.

If a fixture raises ``unittest.case.SkipTest`` during
``start_fixture`` all the tests in the current file will be skipped.
This makes it possible to skip the tests if some optional
configuration (such as a particular type of database) is not
available.
2 changes: 1 addition & 1 deletion gabbi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
# under the License.
"""See gabbi.driver and gabbbi.case."""

__version__ = '0.3.3'
__version__ = '0.4.0'
11 changes: 9 additions & 2 deletions gabbi/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.

from unittest import case
from unittest import suite

from . import fixture
Expand All @@ -24,6 +25,9 @@ class GabbiSuite(suite.TestSuite):
The suite wraps the tests with a set of nested context managers that
operate as fixtures.
If a fixture raises unittest.case.SkipTest during setup, all the
tests in this suite will be skipped.
"""

def run(self, result, debug=False):
Expand All @@ -39,7 +43,10 @@ def run(self, result, debug=False):
fixtures = self._tests[0].fixtures
except AttributeError:
pass
with fixture.nest([fix() for fix in fixtures]):
result = super(GabbiSuite, self).run(result, debug)
try:
with fixture.nest([fix() for fix in fixtures]):
result = super(GabbiSuite, self).run(result, debug)
except case.SkipTest as exc:
[result.addSkip(test, str(exc)) for test in self._tests]

return result

0 comments on commit 3bb36fa

Please sign in to comment.