Skip to content
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

Replace requests_mock with responses #2165

Merged
merged 6 commits into from
Mar 28, 2023
Merged

Replace requests_mock with responses #2165

merged 6 commits into from
Mar 28, 2023

Conversation

edmundmiller
Copy link
Contributor

@edmundmiller edmundmiller commented Jan 22, 2023

PR checklist

  • This comment contains a description of changes (with reason)
  • CHANGELOG.md is updated
  • If you've fixed a bug or added code that should be tested, add tests!
  • Documentation in docs is updated

Just some yak shaving, responses has some nice features that might improve testing in the future such as recording responses to files.

@edmundmiller edmundmiller self-assigned this Jan 22, 2023
@edmundmiller edmundmiller changed the base branch from master to dev January 22, 2023 23:40
@nf-core nf-core deleted a comment from github-actions bot Jan 23, 2023
tests/modules/create.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Mar 27, 2023

Codecov Report

Merging #2165 (376a2d3) into dev (376a2d3) will not change coverage.
The diff coverage is n/a.

❗ Current head 376a2d3 differs from pull request most recent head f4747bf. Consider uploading reports for the commit f4747bf to get more accurate results

@@           Coverage Diff           @@
##              dev    #2165   +/-   ##
=======================================
  Coverage   71.99%   71.99%           
=======================================
  Files          78       78           
  Lines        8385     8385           
=======================================
  Hits         6037     6037           
  Misses       2348     2348           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@github-actions
Copy link
Contributor

Python linting (black) is failing

To keep the code consistent with lots of contributors, we run automated code consistency checks.
To fix this CI test, please run:

  • Install black: pip install black
  • Fix formatting errors in your pipeline: black .

Once you push these changes the test should pass, and you can hide this comment 👍

We highly recommend setting up Black in your code editor so that this formatting is done automatically on save. Ask about it on Slack for help!

Thanks again for your contribution!

@edmundmiller edmundmiller force-pushed the responses branch 3 times, most recently from 418399c to aa770e0 Compare March 27, 2023 23:44
edmundmiller added a commit that referenced this pull request Mar 28, 2023
@edmundmiller edmundmiller marked this pull request as ready for review March 28, 2023 02:51
Copy link
Member

@mirpedrol mirpedrol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you! I left some comments out of curiosity 😄

Also, to add to the discussion, today we were talking with @fabianegli about adding pytest fixtures to modularize the set_up() for different tests, which might be related with this mocking, I think both can complement each other, but maybe Fabian can develop more on his idea.

with requests_mock.Mocker() as mock:
subworkflow_create = nf_core.subworkflows.SubworkflowCreate(root_dir, "test_subworkflow", "@author", True)
subworkflow_create.create()
# TODO Add a mock here
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was there an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There wasn't an error, but responses throws an error if the mock doesn't get used (meaning it's not needed) and when I added the mock calls neither of them were used. So I just removed the mock there for now.

module_create = nf_core.modules.ModuleCreate(
self.pipeline_dir, "trimgalore", "@author", "process_single", True, True, conda_name="trim-galore"
)
module_create.create()
with requests_cache.disabled():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which cache is this affecting? Wondering if it ignores the cloning of the modules repository and then we have to clone it again for every test, but it doesn't seem so when I try to run the test :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's not the creation of that, it's just any queries that are running inside that code. For example, if you try to hit anaconda here. It was masking the mock and what I was stuck on months ago because the "mock wasn't used" because it was using the cache.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, that's interesting!

@edmundmiller
Copy link
Contributor Author

Also, to add to the discussion, today we were talking with @fabianegli about adding pytest fixtures to modularize the set_up() for different tests, which might be related with this mocking, I think both can complement each other, but maybe Fabian can develop more on his idea.

Looking forward to it! I think responses has some cool features, just wanted to keep this PR 1-to-1 with the current implementation!

@fabianegli
Copy link
Contributor

I'll wait to open the PR until this one is merged. It will save some time otherwise spent on merge conflict resolution. Sorry for the wait, @emiller88

@edmundmiller edmundmiller merged commit f8ef685 into dev Mar 28, 2023
@edmundmiller edmundmiller deleted the responses branch March 28, 2023 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants