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

Issue #402: Fix tests that fail as a result of running pytest with no flags #404

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

baileythegreen
Copy link
Contributor

CLI parsing in pyani_script.py and some test files made the implicit assumption that they were dealing with a pyani command; however, these files also parse the command line when a pytest command is issued. When:

$ pytest

is run on its own (with no flags), this therefore caused things to fail.

Closes #402.

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality not to work as expected)
  • This change requires a documentation update
  • This is a documentation update

Action Checklist

  • Work on a single issue/concept (if there are multiple separate issues to address, please use a separate pull request for each)
  • Fork the pyani repository under your own account (please allow write access for repository maintainers)
  • Set up an appropriate development environment (please see CONTRIBUTING.md)
  • Create a new branch with a short, descriptive name
  • Work on this branch
    • style guidelines have been followed
    • new code is commented, especially in hard-to-understand areas
    • corresponding changes to documentation have been made
    • tests for the change have been added that demonstrate the fix or feature works
  • Test locally with pytest -v non-passing code will not be merged
  • Rebase against origin/master
  • Check changes with flake8 and black before submission
  • Commit branch
  • Submit pull request, describing the content and intent of the pull request
  • Request a code review
  • Continue the discussion at Pull requests section in the pyani repository

@baileythegreen baileythegreen added bug something isn't working how it should tests issues relating to tests labels Jun 15, 2022
@baileythegreen baileythegreen added this to the 0.3.0 milestone Jun 15, 2022
@codecov
Copy link

codecov bot commented Jun 15, 2022

Codecov Report

Merging #404 (5676e63) into master (62949c4) will decrease coverage by 0.00%.
The diff coverage is 80.00%.

@@            Coverage Diff             @@
##           master     #404      +/-   ##
==========================================
- Coverage   75.82%   75.81%   -0.01%     
==========================================
  Files          55       55              
  Lines        3747     3750       +3     
==========================================
+ Hits         2841     2843       +2     
- Misses        906      907       +1     

@@ -871,7 +871,8 @@ def process_arguments(args: Optional[Namespace]) -> Namespace:
shows the version and exits.
"""
# Catch execution with no arguments
if len(sys.argv) == 1:
# But only for the `pyani` executable (`pytest` was also being caught here)
Copy link
Owner

Choose a reason for hiding this comment

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

I don't understand why endswith() is used in preference to ==. What is your thinking, here?

Also, the pyani command would not executeaverage_nucleotide_identity.py - the command for this is average_nucleotide_identity.py (see this line), so should this not be testing for average_nucleotide_identity.py rather than pyani?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the == part, see my response below.

Also, the pyani command would not execute average_nucleotide_identity.py

Yes, you're right; that was a mistake on my part.

Copy link
Owner

Choose a reason for hiding this comment

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

So long as you make the change such that v0.2 tests for average_nucleotide_identity.py this part of the conversation can be resolved.

@@ -103,6 +103,10 @@ def run_main(argv: Optional[List[str]] = None) -> int:
sys.stderr.write(f"{VERSION_INFO}\n")
return 0

# If the command run is not pyani (e.g., `pytest`, then we
# don't want to apply pyani-specific checks)
if len(sys.argv) == 1 and not sys.argv[0].endswith("pyani"):
Copy link
Owner

Choose a reason for hiding this comment

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

I don't understand why endswith() is used in preference to ==. What is your thinking, here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because sys.argv[0] in this case is not pyani, but:

/Users/baileythegreen/Software/miniconda3/envs/pyani_dev/bin/pyani.

The same goes for pytest above. I tried == first, and it failed.

Copy link
Owner

@widdowquinn widdowquinn Jun 20, 2022

Choose a reason for hiding this comment

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

I see. It would be more robust to either (i) treat sys.argv[0] as a Path object and test for equality using the .name attribute, or (ii) .split("/") the passed path and test the last element in the resulting collection. Using .endswith() does give a True value with the case you want, but also in cases where the executable is not simply pyani (or pytest, in the case where you'r echecking for that):

>>> from pathlib import Path
>>> pyani_path = "/my/path/to/pyani"
>>> notpyani_path = "/my/path/to/notpyani"
>>> Path(pyani_path).name
'pyani'
>>> Path(notpyani_path).name
'notpyani'
>>> pyani_path.split("/")[-1]
'pyani'
>>> notpyani_path.split("/")[-1]
'notpyani'
>>> pyani_path.endswith("pyani")
True
>>> notpyani_path.endswith("pyani")
True

Copy link
Contributor Author

@baileythegreen baileythegreen Jun 20, 2022

Choose a reason for hiding this comment

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

I mentioned in our last meeting that I'd thought of a better way to do it, and I think I said that was using a Path() object; you said you thought not testing for pytest specifically would be better—and I thought part of the implication there was you didn't want Path() used.

I must have misunderstood; I can of course use Path() and test for whether the program is pyani, or not.

@baileythegreen
Copy link
Contributor Author

Sorry, I missed there were comments on this the other day; I only saw the email about codecov.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something isn't working how it should tests issues relating to tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test_cli_parsing() tests fail when pytest is run with no flags
2 participants