Skip to content

Instantly share code, notes, and snippets.

@rozza
Created July 30, 2010 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rozza/500598 to your computer and use it in GitHub Desktop.
Save rozza/500598 to your computer and use it in GitHub Desktop.
saves and restores sys.stdout
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