Skip to content
Data fixtures for pytest made simple
Python
Branch: master
Clone or download

Latest commit

Latest commit d7b45e2 May 13, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
datafixtures Release v0.1.0 May 11, 2020
tests Add 'datafix_read' fixture. May 11, 2020
.coveragerc Start here. May 11, 2020
.gitignore Start here. May 11, 2020
.travis.yml Start here. May 11, 2020
AUTHORS Start here. May 11, 2020
CHANGELOG Release v0.1.0 May 11, 2020
CONTRIBUTING Start here. May 11, 2020
INSTALL Start here. May 11, 2020
LICENSE Start here. May 11, 2020
MANIFEST.in Start here. May 11, 2020
README.rst Update README.rst May 13, 2020
setup.cfg Start here. May 11, 2020
setup.py Start here. May 11, 2020
tox.ini Start here. May 11, 2020

README.rst

pytest-datafixtures

https://github.com/idlesign/pytest-datafixtures

release lic ci coverage

Description

Data fixtures for pytest made simple

Offers fixtures for your tests to simplify data fixtures access. Makes use of Python's native Path objects.

Data fixtures (files) expected to be stored in datafixtures directory next to your test modules:

tests
|-- datafixtures
|-- test_basic.py
|
|-- subdirectory
|---- datafixtures
|---- test_other.py

Fixtures

  • datafix_dir - Path object for data fixtures directory from the current test module's directory.
  • datafix - Path object for a file in data fixtures directory with the same name as the current test function.
  • datafix_read - Returns contents of a data fixture by it's name.

datafix_dir

Access data fixtures directory:

def test_me(datafix_dir):

    # datafix_dir returns a Path object.
    assert datafix_dir.exists()

    # Gather data fixtures filenames.
    files = list(f'{file.name}' for file in datafix_dir.iterdir())

    # Read some fixture as text.
    # The same as using `datafix_read` fixture (see below).
    filecontent = (datafix_dir / 'expected.html').read_text()

    # Or read binary.
    filecontent = (datafix_dir / 'dumped.bin').read_bytes()

datafix

Access a data fixture with test name:

def test_me(datafix):
    # Read datafixtures/test_me.txt file
    filecontents = datafix.with_suffix('.txt').read_text()

datafix_read

Access contents of a data fixture by it's name:

def test_datafix_read(datafix_read):
    # Read datafixtures/expected.html file
    filecontents = datafix_read('expected.html')

Requirements

  • Python 3.6+
You can’t perform that action at this time.