Custom TempFile “Fixture

Pytest fixtures.

Well, sort of. Pytest does not allow for class based fixtures, so the best alternative in this case is to create a module local to the tests that can easily imported and used within them.

This module contains the code for a CustomTempFile class, as well as several variables representing longer file contents needed in some tests.

tests.custom_tmp_file.BIOMART_RESPONSE

Example response from a BioMart query, pre-processing.

Type

str

tests.custom_tmp_file.BIOMART_CONTENTS

Example response from a BioMart query, post-processing.

Type

str

tests.custom_tmp_file.GTEX_CONTENTS

Example response from a GTEx query.

Type

str

tests.custom_tmp_file.MANE_CONTENTS

Minimal MANE file contents.

Type

str

class tests.custom_tmp_file.CustomTempFile(content: str)

Create a temporary file with custom content.

This is best used within a context manager to insure proper file clean up.

Adapted from a StackOverflow answer.

Parameters

content (str) – Content of created temporary file.

Examples

>>> with CustomTempFile('Hello World') as tmp:
>>>     with open(tmp.filename, 'r') as file:
>>>         assert file.read() == 'Hello World'
property filename: str

Return the filename of the created file.

Returns

The filename.

Return type

str