WayScience / CytoSnake

Orchestrating high-dimensional cell morphology data processing pipelines
https://cytosnake.readthedocs.io
Creative Commons Attribution 4.0 International
3 stars 3 forks source link

Improving Functional Test With `pytest` Fixtures #75

Closed axiomcura closed 1 year ago

axiomcura commented 1 year ago

modified from EmbeddedArtistry

Description

Thank you for your contribution to pycytominer! Please succinctly summarize your proposed change. What motivated you to make this change?

Please also link to any relevant issues that your code is associated with.


This PR introduces using pytest fixtures

The main goal of this PR is to leverage fixtures to make functional test much easier. Below is a diagram on how fixtures and helper functions are implemented in a single test.

functional-testing-diagram drawio

Simple diagram illustrating how functional tests work: starting for the right side, (red) is the fixture used to generate temporary testing directories per test, (yellow) is the functional test with all the steps done, (green) is the a helper function known as prepare_data() that does all the heavy lifting to transporting datasets into the testing folder.

The diagram illustrates the implementation of CytoSnake's functional tests. Initially, a fixture (depicted in red) serves as input for the functional test (depicted in yellow). Within this process, pytest identifies that the fixture includes a path where the test should occur, hence generating a temporary directory. Additionally, the fixture's teardown function ensures that pytest removes the testing directory once the test finishes. Overall, leveraging these fixtures eliminates the need for developers to manually create and delete temporary directories for every test.

Additionally, a new function called prepare_dataset() has been added. This function primarily serves to facilitate the easy selection and transfer of data to a testing directory. It requires just one input: the desired dataset's name. The dataset names correspond to the directory names located within cytosnake/tests/functional/dataset.

Additional changes

New module

Documentation changes

Future PR

A future pull request will cover the rationale, motivations, and the design process behind the implementation of functional tests in CytoSnake. This PR will also provide a standardized guide detailing how to effectively document functional tests on the Read the Docs (RTD) website.


What is the nature of your change?functional

Checklist

Please ensure that all boxes are checked before indicating that a pull request is ready for review.

axiomcura commented 1 year ago

@d33bs Mind giving this a second round of review?

Here are some changes that I have done:

axiomcura commented 1 year ago

@d33bs I have added comments and suggestions. I'll be merging until the end of the day if you do not have any more comments or suggestions.

Thank you!