Fixtures icon

Fixtures For Linux

  n/a
The Apache License 2.0    

Fixtures, reusable state for writing clean tests and more. #Write tests  #Unit testing  #Unit  #Testing  #Tests  #Python  

Description

Free Download

Fixtures is a tool that defines a Python contract for reusable state / support logic, primarily for unit testing. Helper and adaption logic is included to make it easy to write your own fixtures using the fixtures contract. Glue code is provided that makes using fixtures that meet the Fixtures contract in unittest compatible test cases easy and straight forward.

Standard Python unittest.py provides no obvious method for making and reusing state needed in a test case other than by adding a method on the test class. This scales poorly - complex helper functions propogating up a test class hierarchy is a regular pattern when this is done. Mocking while a great tool doesn't itself prevent this (and helpers to mock complex things can accumulate in the same way if placed on the test class).

By defining a uniform contract where helpers have no dependency on the test class we permit all the regular code hygiene activities to take place without the distorting influence of being in a class hierarchy that is modelling an entirely different thing - which is what helpers on a TestCase suffer from.

A Fixture represents some state. Each fixture has attributes on it that are specific to the fixture. For instance, a fixture representing a directory that can be used for temporary files might have a attribute 'path'.

Minimally, subclass Fixture, define setUp to initialize your state and schedule a cleanup for when cleanUp is called and you're done:

>>> import unittest >>> import fixtures >>> class NoddyFixture(fixtures.Fixture): ... def setUp(self): ... super(NoddyFixture, self).setUp() ... self.frobnozzle = 42 ... self.addCleanup(delattr, self, 'frobnozzle')

This will initialize frobnozzle when setUp is called, and when cleanUp is called get rid of the frobnozzle attribute.

There is a helper for adapting a function or function pair into Fixtures. it puts the result of the function in fn_result:

>>> import os.path >>> import shutil >>> import tempfile >>> def setup_function(): ... return tempfile.mkdtemp() >>> def teardown_function(fixture): ... shutil.rmtree(fixture) >>> fixture = fixtures.FunctionFixture(setup_function, teardown_function) >>> fixture.setUp() >>> print os.path.isdir(fixture.fn_result) True >>> fixture.cleanUp()

The example above introduces some of the Fixture API. In order to be able to clean up after a fixture has been used, all fixtures define a cleanUp method which should be called when a fixture is finished with.

Because its nice to be able to build a particular set of related fixtures in advance of using them, fixtures also have define a setUp method which should be called before trying to use them.

One common desire with fixtures that are expensive to create is to reuse them in many test cases; to support this the base Fixture also defines a reset which calls self.cleanUp(); self.setUp(). Fixtures that can more efficiently make themselves reusable should override this method. This can then be used with multiple test state via things like testresources, setUpClass, or setUpModule.

When using a fixture with a test you can manually call the setUp and cleanUp methods. More convenient though is to use the included glue from fixtures.TestWithFixtures which provides a mixin defining useFixture (camel case because unittest is camel case throughout) method. It will call setUp on the fixture, call self.addCleanup(fixture) to schedule a cleanup, and return the fixture. This lets one write: >>> import testtools >>> import unittest

Note that we use testtools TestCase here as we need to guarantee a TestCase.addCleanup method.

 >>> class NoddyTest(testtools.TestCase, fixtures.TestWithFixtures):  ... def test_example(self):  ... fixture = self.useFixture(NoddyFixture())  ... self.assertEqual(42, fixture.frobnozzle)  >>> result = unittest.TestResult()  >>> _ = NoddyTest('test_example').run(result)  >>> print result.wasSuccessful()  True

Fixtures implement the context protocol, so you can also use a fixture as a context manager:

>>> with fixtures.FunctionFixture(setup_function, teardown_function) as fixture: ... print os.path.isdir(fixture.fn_result) True

System requirements

Fixtures 0.3.14

add to watchlist add to download basket send us an update REPORT
  runs on:
Linux
  filename:
fixtures-0.3.14.tar.gz
  main category:
Programming
  developer:
  visit homepage

7-Zip 23.01 / 24.04 Beta

An intuitive application with a very good compression ratio that can help you not only create and extract archives, but also test them for errors
7-Zip

Microsoft Teams 24060.3102.2733.5911 Home / 1.7.00.7956 Work

Effortlessly chat, collaborate on projects, and transfer files within a business-like environment by employing this Microsoft-vetted application
Microsoft Teams

4k Video Downloader 1.5.3.0080 Plus / 4.30.0.5655

Export your favorite YouTube videos and playlists with this intuitive, lightweight program, built to facilitate downloading clips from the popular website
4k Video Downloader

Zoom Client 6.0.3.37634

The official desktop client for Zoom, the popular video conferencing and collaboration tool used by millions of people worldwide
Zoom Client

IrfanView 4.67

With support for a long list of plugins, this minimalistic utility helps you view images, as well as edit and convert them using a built-in batch mode
IrfanView

Context Menu Manager 3.3.3.1

Customize Windows’ original right-click context menu using this free, portable and open-source utility meant to enhance your workflow
Context Menu Manager

ShareX 16.0.1

Capture your screen, create GIFs, and record videos through this versatile solution that includes various other amenities: an OCR scanner, image uploader, URL shortener, and much more
ShareX

Bitdefender Antivirus Free 27.0.35.146

Feather-light and free antivirus solution from renowned developer that keeps the PC protected at all times from malware without requiring user configuration
Bitdefender Antivirus Free

Windows Sandbox Launcher 1.0.0

Set up the Windows Sandbox parameters to your specific requirements, with this dedicated launcher that features advanced parametrization
Windows Sandbox Launcher

calibre 7.9.0

Effortlessly keep your e-book library thoroughly organized with the help of the numerous features offered by this efficient and capable manager
calibre

38% discount
Bitdefender Antivirus Free
  • Bitdefender Antivirus Free
  • Windows Sandbox Launcher
  • calibre
  • 7-Zip
  • Microsoft Teams
  • 4k Video Downloader
  • Zoom Client
  • IrfanView
  • Context Menu Manager
  • ShareX
essentials


Click to load comments
This enables Disqus, Inc. to process some of your data. Disqus privacy policy