O'Reilly logo

Python Testing Cookbook by Greg L. Turnquist

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Defining a subset of test cases using import statements

Create a Python module that selectively imports what test cases to run.

How to do it...

With these steps, we will explore selectively picking a smaller set of tests to facilitate a faster test run.

  1. Create a test module called recipe59_test.py for writing some tests against our network application.
    import logging
    from network import *
    import unittest
    from springpython.database.factory import *
    from springpython.database.core import *
  2. Create a test case that removes the database connection and stubs out the data access functions.
    class EventCorrelatorUnitTests(unittest.TestCase): def setUp(self): db_name = "recipe59.db" factory = Sqlite3ConnectionFactory(db=db_name) self.correlator = EventCorrelator(factory) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required