Skip to main content

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

Project description

============
Introduction
============

.. image:: https://badge.fury.io/py/pytest-testdirectory.svg
:target: https://badge.fury.io/py/pytest-testdirectory

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.

.. contents:: Table of Contents:
:local:

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
=====

* Why use an ``src`` folder (https://hynek.me/articles/testing-packaging/).
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: https://packaging.python.org/distributing/


Project details


Download files

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

Source Distribution

pytest-testdirectory-3.1.0.tar.gz (126.1 kB view details)

Uploaded Source

Built Distribution

pytest_testdirectory-3.1.0-py2.py3-none-any.whl (11.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pytest-testdirectory-3.1.0.tar.gz.

File metadata

  • Download URL: pytest-testdirectory-3.1.0.tar.gz
  • Upload date:
  • Size: 126.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/32.3.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.3

File hashes

Hashes for pytest-testdirectory-3.1.0.tar.gz
Algorithm Hash digest
SHA256 cd8372b805a17a41439ad254460885aaa7d114d73bbc9d8efa676142650b07cc
MD5 b1a7f858563e74da07ee2e2539632702
BLAKE2b-256 77b1f07a0c0256083747f4aad079d8ebb38f37c86ec595b8b88d03747cca43eb

See more details on using hashes here.

File details

Details for the file pytest_testdirectory-3.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_testdirectory-3.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e045d44ac7e6736ddd7c712db4498b820819f24136ac0bebfda8554c59aa1c46
MD5 d7687fb556ef32d051a75b072a6dcf15
BLAKE2b-256 cdb56a51c41d8679b685da1637b3e62e3126695efdf477cbe2a5c23fc4fd6503

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page