-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improving Functional Test With pytest
Fixtures
#75
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great PR. The documentation in the code looks amazing. The .cli.md
files are above me so I can't provide much feedback... if you have time and could explain in person, that would be great! Thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! I left a few comments and suggestions throughout this review. Please don't hesitate to let me know if you have any questions or concerns.
I'm marking this as a "comment" review for now as I wasn't able to successfully run tests from the changes in this PR (running into a FileNotFoundError
when running pytest
for tests test_multiplates_with_multi_platemaps
, test_one_plate_one_platemap
, and test_multiplate_maps_no_barcode
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about the future of CytoSnake testing, would it be useful to provide these datasets without the functional
distinction in the directory path? For example, would these ever be used for unit or integration testing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. I think that's a great idea! When I was developing this, I had no idea how the datasets should be implemented because the unit and workflow tests were not developed yet.
cytosnake/tests/functional/datasets/standard_sqlite_single/plate_data1.sqlite
Outdated
Show resolved
Hide resolved
Co-authored-by: Dave Bunten <ekgto445@gmail.com>
Co-authored-by: Dave Bunten <ekgto445@gmail.com>
@d33bs Mind giving this a second round of review? Here are some changes that I have done:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work in addressing the comments and making changes! I've left a few more comments and generally felt things looked good. Please don't hesitate to let me know if you have any questions.
tests/functional/pytest.ini
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider removing this file and making use of the pyproject.toml
file + style for this configuration. Using the pyproject.toml
file would help reduce file/code additions and also help with test invocation from the project root directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done: 7b1291f
tests/functional/test_cli.py
Outdated
assert proc.returncode == 0 | ||
assert data_folder.exists() | ||
assert cytosnake_file.exists() | ||
assert barcodes_in_datafolder.exists() | ||
assert metadata_in_datafolder.exists() | ||
assert all([str(plate_data).endswith(".sqlite") for plate_data in all_plates]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeing how this pattern repeats, is there an opportunity for a common utility function for checking these things to help reduce code duplication?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done! f2cc176
tests/functional/test_cli.py
Outdated
assert proc.returncode == 0 | ||
assert data_folder.exists() | ||
assert cytosnake_file.exists() | ||
assert metadata_in_datafolder.exists() | ||
assert all([str(plate_data).endswith(".sqlite") for plate_data in all_plates]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the addition of non-zero data for testing are there other more specific data-orientated tests which could be added here or elsewhere to help with validation? This could come in, for example, the form of data shape, types, unique values, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, no, those tests will be done within the either unit testing or workflow testing. The functional tests just focus on emulating user experience with the CLI. For example, setting up your directory to be a project directory. No files are being open and read into memory in this step.
""" | ||
|
||
# transfer data to testing folder | ||
test_utils.prepare_dataset(test_data_name="nf1-data", test_dir_path=testing_dir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeing how this pattern repeats, would this be a good opportunity for a fixture?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about this earlier and I feel like the design of using fixture that require parameters are a bit daunting and may be not easy for new developers.
Below is an example if prepare_dataset()
becomes a fixture:
@pytest.mark.parametrize("prepare_data", ["nf1"], indirect=True)
def text_example(testing_dir, prepare_dataset) -> None:
# testing code below
However, if a redesign of the testing framework is conducted, then I will consider this approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did this and the related files come from other locations (and include efforts from other people)? If so, consider adding a reference of some kind to help document their contributions to this project (for example, through a CITATION.cff file using the references
key).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added: 1c6286d
Co-authored-by: Dave Bunten <ekgto445@gmail.com>
@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! |
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
fixturesThe 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.
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 thatpytest
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 withincytosnake/tests/functional/dataset
.Additional changes
New module
test_utils
for storing general helper functions, making testing development much easier.Documentation changes
test_utils
module has now been added into the RTD documentation website source codeFuture 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.