Skip to main content

Introduction

PyPi Waf Python Tests Black Flake8 Pip Install

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 directories.

Installation

To install pytest-testdirectory:

pip install pytest-testdirectory

Usage

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.

Example:

def test_this_function(testdirectory):
    images = testdirectory.mkdir('images')
    images.copy_files('test/images/*')

    r = testdirectory.run('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 behavior.

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/testdirectory.py and the corresponding unit test is in test/test_testdirectory.py 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 (https://waf.io/) augmented with dependency resolution capabilities: https://github.com/steinwurf/waf

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.

Tests

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.

Notes

Metadata

Release files for pytest-testdirectory 5.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for pytest-testdirectory 5.0.0
File Interpreter ABI Platform
pytest_testdirectory-5.0.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Release files / pytest_testdirectory-5.0.0-py2.py3-none-any.whl

Download URL pytest_testdirectory-5.0.0-py2.py3-none-any.whl
Size 10.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
38f78c33b57e4ab8968c2d1d021731d7eee7a9b5613b63db4679d5363da0db2e
BLAKE2b-256 checksum
How to use checksums
d9b7fbf9030106cd3aa915b7af6bfa5dca4f5423338cdd02b98898f01946f496
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Security for pytest-testdirectory 5.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page