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

Include functional tests in code coverage #899

Merged
merged 3 commits into from
May 24, 2022
Merged

Conversation

huddlej
Copy link
Contributor

@huddlej huddlej commented Apr 21, 2022

Description of proposed changes

Use the default coverage report file .coverage for unit and functional
tests, running Augur in functional tests through an alias that runs
coverage in append mode. Then, use the coverage xml command to generate
the XML report needed by the codecov tool.

Related issues

Fixes #688

Use the default coverage report file `.coverage` for unit and functional
tests, running Augur in functional tests through an alias that runs
coverage in append mode. Then, use the coverage xml command to generate
the XML report needed by the codecov tool.
@huddlej huddlej marked this pull request as ready for review April 21, 2022 20:26
@codecov
Copy link

codecov bot commented Apr 21, 2022

Codecov Report

Merging #899 (072404e) into master (002c44f) will increase coverage by 24.89%.
The diff coverage is n/a.

@@             Coverage Diff             @@
##           master     #899       +/-   ##
===========================================
+ Coverage   34.62%   59.51%   +24.89%     
===========================================
  Files          42       43        +1     
  Lines        6007     6062       +55     
  Branches     1538     1557       +19     
===========================================
+ Hits         2080     3608     +1528     
+ Misses       3854     2199     -1655     
- Partials       73      255      +182     
Impacted Files Coverage Δ
bin/augur 80.00% <0.00%> (ø)
augur/util_support/date_disambiguator.py 96.07% <0.00%> (+1.96%) ⬆️
augur/import_beast.py 10.71% <0.00%> (+3.57%) ⬆️
augur/util_support/color_parser.py 100.00% <0.00%> (+3.57%) ⬆️
augur/util_support/node_data_reader.py 100.00% <0.00%> (+4.87%) ⬆️
augur/sequence_traits.py 14.92% <0.00%> (+5.97%) ⬆️
augur/distance.py 54.90% <0.00%> (+6.53%) ⬆️
augur/lbi.py 21.91% <0.00%> (+9.58%) ⬆️
augur/reconstruct_sequences.py 27.58% <0.00%> (+10.34%) ⬆️
augur/version.py 66.66% <0.00%> (+16.66%) ⬆️
... and 20 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 002c44f...072404e. Read the comment docs.

@huddlej huddlej requested a review from victorlin April 21, 2022 21:02
Copy link
Member

@tsibley tsibley left a comment

Choose a reason for hiding this comment

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

Nice to see what these tests cover! One comment on approach below.

@@ -7,7 +7,8 @@ Running from the test data directory allows us to use relative paths that won't
$ TEST_DATA_DIR="$TESTDIR/zika"
$ mkdir -p "$TMP/out"
$ pushd "$TEST_DATA_DIR" > /dev/null
$ export AUGUR="../../../bin/augur"
$ export COVERAGE_FILE="$TESTDIR/../../.coverage"
$ export AUGUR="coverage run -a --rcfile=$TESTDIR/../../.coveragerc ../../../bin/augur"
Copy link
Member

Choose a reason for hiding this comment

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

Instead of defining AUGUR this way with coverage run … in every cram test file, can we instead run cram itself under coverage instead in ci.yaml?

This would avoid the increased boilerplate in each cram test file but also mean that coverage isn't observed for local cram runs unless someone opts into it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried this originally, but I found it only produced coverage of cram itself. It's likely I was not invoking coverage properly though. I tried something like this first:

coverage run \
  --rcfile=.coveragerc \
  `which cram` \
  --shell=/bin/bash \
  tests/functional/parse.t tests/functional/ancestral.t

And then coverage report produces:

Name                                                Stmts   Miss Branch BrPart  Cover
-------------------------------------------------------------------------------------
/Users/jlhudd/miniconda3/envs/nextstrain/bin/cram       6      1      0      0    83%
-------------------------------------------------------------------------------------
TOTAL                                                   6      1      0      0    83%

I also tried forcing a report on augur alone by adding --source augur to the coverage command above, but this produced a warning of Coverage.py warning: No data was collected. (no-data-collected).

Another way we could remove some of the above boilerplate code would be to export absolute paths to COVERAGE_FILE and COVERAGE_RCFILE outside of Cram and then we'd be back to one line like this which isn't too bad:

  $ export AUGUR="coverage run -a ../../../bin/augur"

Copy link
Member

@tsibley tsibley Apr 26, 2022

Choose a reason for hiding this comment

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

Hmm. Reducing boilerplate is nice, and +1 for pulling out the coverage args into env vars set outside of cram, but my main point is to not to bake in coverage to the tests but have it be a separate concern (e.g. CI's concern).

If AUGUR was defined in the cram tests as:

export AUGUR="${AUGUR:-../../bin/augur}"

then it could be overridden by ci.yaml to include coverage run … when invoking cram.

If you'd rather not go down this path, that's fine. This isn't a merge-blocking suggestion. I bring this up only because in my experience it's better to have coverage tracing happen outside of tests (i.e. the tests are unaware) rather than as integrated into the tests themselves, so this stood out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I totally agree! I just couldn't figure out how to actually accomplish that separation of concerns. That's part of why I asked for @victorlin's help here, but happy to have any other help we can get!

Copy link
Member

Choose a reason for hiding this comment

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

Ok! Since I had already thought about this above, I went ahead and pushed a commit to separate these out. We'll see if it works…

Copy link
Member

Choose a reason for hiding this comment

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

I don't think I would look for version-specific code coverage, though.

Nod. It's less about looking for it explicitly and more that if we don't test version-specific code paths than coverage has some upper limit that's not 100%. :-)

Copy link
Member

Choose a reason for hiding this comment

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

@tsibley I like the diff above since it solves #845. Maybe it'll take slightly longer to run but not a big deal.

Are there version-dependent code paths in Augur? If not, is it likely in the future?

Copy link
Member

Choose a reason for hiding this comment

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

Not sure. Nothing obvious from a simple grep on sys.version_info, though that's not comprehensive. But probably not any now, and not very likely in the future (though not unreasonable)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@victorlin Do you want to apply the diff above before we merge? I don't feel strongly either way...

Copy link
Member

Choose a reason for hiding this comment

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

@huddlej I'll put it in a new PR since this one looks good, and we can compare the CI differences a bit easier that way.

…I workflow

This avoids baking in coverage to the tests and lets it remain a
separate concern (e.g. CI's concern).  In my experience it's better to
have coverage tracing happen outside of tests (i.e. the tests are
unaware) rather than as integrated into the tests themselves.

Partially reverts commit 723d609, which
added code for coverage to each cram test file.

I chose to use the github.workspace context var in the CI workflow so I
could use the "env:" block for the job step.  Alternatively, we could
use `realpath` to construct an `env AUGUR=… …` call chaining to the
`cram …` invocation, but that seemed slightly messier to me.
Copy link
Member

@victorlin victorlin left a comment

Choose a reason for hiding this comment

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

Just got around to looking at this, looks good to me.

@victorlin
Copy link
Member

@huddlej good to merge based on Slack discussion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Include functional tests from cram in coverage reports
3 participants