LTA’s Conftest

Fixtures for pytest.

tests.conftest.binary_df() pandas.core.frame.DataFrame

Create a binary dataframe.

This creates a binary dataframe with a known distribution 1s and 0s. This allows for prior knowledge about thresholding to confirm testing.

Returns

A binary dataframe of known properties

Return type

pd.DataFrame

tests.conftest.create_df() Callable[[Tuple[int, int], int, List[str], int, List[str]], pandas.core.frame.DataFrame]

Create a “random” dataframe.

Technically, pytest fixtures don’t take arguments. A form of argument passing can be achieved with indirect parametrization, but this iterates over the arguments, running each test multiple times. This isn’t quite what we want, as we need to create (sometimes multiple) dataframes per test, running each test once. This is a bit of cheeky magic to create a fixture that “accepts” arguments. In reality, it is returning a function that does what we want.

Returns

A function that creates a random numeric dataframe. The first argument is the shape of the dataframe. The second and third argument is the number of levels and names for the row multiindex. The fourth and fifth argument is the number of levels and names for the column multiindex.

Return type

Callable[[Tuple[int, int], int, List[str], int, List[str]], pd.DataFrame]