Created
July 30, 2010 14:25
-
-
Save rozza/500598 to your computer and use it in GitHub Desktop.
saves and restores sys.stdout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
class ResultPlugin(object): | |
""" | |
Captures the TestResult object for later inspection. | |
nose doesn't return the full test result object from any of its runner | |
methods. Pass an instance of this plugin to the TestProgram and use | |
``result`` after running the tests to get the TestResult object. | |
""" | |
name = "result" | |
enabled = True | |
def finalize(self, result): | |
self.result = result | |
class DjangoSetUpPlugin(object): | |
""" | |
Configures Django to setup and tear down the environment. | |
This allows coverage to report on all code imported and used during the | |
initialisation of the test runner. | |
""" | |
name = "django setup" | |
enabled = True | |
def __init__(self, runner): | |
super(DjangoSetUpPlugin, self).__init__() | |
self.runner = runner | |
self.sys_stdout = sys.stdout | |
def begin(self): | |
"""Setup the environment""" | |
sys_stdout = sys.stdout | |
sys.stdout = self.sys_stdout | |
self.runner.setup_test_environment() | |
self.old_names = self.runner.setup_databases() | |
sys.stdout = sys_stdout | |
def finalize(self, result): | |
"""Destroy the environment""" | |
self.runner.teardown_databases(self.old_names) | |
self.runner.teardown_test_environment() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment