-
Notifications
You must be signed in to change notification settings - Fork 55
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
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ 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) |
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 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
?
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.
For the ==
part, see my response below.
Also, the
pyani
command would not executeaverage_nucleotide_identity.py
Yes, you're right; that was a mistake on my part.
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.
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.
pyani/scripts/pyani_script.py
Outdated
@@ -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"): |
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 don't understand why endswith()
is used in preference to ==
. What is your thinking, here?
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.
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.
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 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
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 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.
Sorry, I missed there were comments on this the other day; I only saw the email about |
CLI parsing in
pyani_script.py
and some test files made the implicit assumption that they were dealing with apyani
command; however, these files also parse the command line when a pytest command is issued. When:is run on its own (with no flags), this therefore caused things to fail.
Closes #402.
Type of change
Action Checklist
pyani
repository under your own account (please allow write access for repository maintainers)CONTRIBUTING.md
)pytest -v
non-passing code will not be mergedorigin/master
flake8
andblack
before submissionPull requests
section in thepyani
repository