O'Reilly logo

Python Testing Beginner's Guide by Daniel Arbuckle

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

Time for action - creating a package fixture

Now we'll create a fixture that wraps around all the test modules in an entire package.

  1. Add a new file called __init__.py in the tests directory that we created in the last Time for action section. (That's two underbars, the word 'init, and two more underbars). The presence of this file tells Python that the directory is a package. Place the following code inside of __init__.py in the tests directory:
    from mocker import Mocker from datetime import datetime mocker = Mocker() def setup(): fake_datetime = mocker.replace(datetime) fake_datetime.now() mocker.result(datetime(year = 2009, month = 6, day = 12, hour = 10, minute = 15, second = 5)) mocker.count(1, None) mocker.replay() def teardown(): mocker.restore() ...

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