Skip to main content

A py.test plugin providing temporary directories in unit tests.

Project description


.. image::

Testing code by invoking executable which potentially creates and deletes
files and directories can be hard and error prone.

The purpose of this module is to simplify this task.

pytest-testdirectory provides a py.test fixture for working with temporary

.. contents:: Table of Contents:


To install pytest-testdirectory::

pip install pytest-testdirectory


To make it easy to use in with py.test the TestDirectory object can be
injected into a test function by using the testdirectory fixture.


def test_this_function(testdirectory):
images = testdirectory.mkdir('images')

r ='imagecompress --path=images')

# r is an RunResult object containing information about the command
# we just executed
assert r.stdout.match('*finished successfully*')

The testdirectory is an instance of TestDirectory and represents an actual
temporary directory somewhere on the machine running the test code. Using
the API we can create additional temporary directories, populate them with
an initial set of files and finally run some executable and observe its

Relase new version

1. Edit NEWS.rst and wscript (set correct VERSION)
2. Run ::

./waf upload

Source code

The main functionality is found in ``src/`` and the
corresponding unit test is in ``test/`` if you
want to play/modify/fix the code this would, in most cases, be the place
to start.

Developer Notes

We try to make our projects as independent as possible of a local system setup.
For example with our native code (C/C++) we compile as much as possible from
source, since this makes us independent of what is currently installed
(libraries etc.) on a specific machine.

To "fetch" sources we use Waf ( augmented with dependency
resolution capabilities:

The goal is to enable a work-flow where running::

./waf configure
./waf build --run_tests

Configures, builds and runs any available tests for a given project, such that
you as a developer can start hacking at the code.

For Python project this is a bit unconventional, but we think it works well.


The tests will run automatically by passing ``--run_tests`` to waf::

./waf --run_tests

This follows what seems to be "best practice" advise, namely to install the
package in editable mode in a virtualenv.


* Why use an ``src`` folder (
tl;dr you should run your tests in the same environment as your users would
run your code. So by placing the source files in a non-importable folder you
avoid accidentally having access to resources not added to the Python
package your users will install...
* Python packaging guide:

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pytest-testdirectory, version 3.1.0
Filename, size File type Python version Upload date Hashes
Filename, size pytest_testdirectory-3.1.0-py2.py3-none-any.whl (11.2 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size pytest-testdirectory-3.1.0.tar.gz (126.1 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page