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

Clean up coverage generation and reporting in tox & travis. #187

Closed
wants to merge 25 commits into from

Conversation

wsanchez
Copy link
Member

@wsanchez wsanchez commented Jun 21, 2017

Summary of what's changing here:

  • tox.ini:
    • Print a coverage report after unit tests, excluding 100% covered files.
    • Add coverage reports (HTML and XML)
    • Add coverage_combine that combines coverage data and fails if coverage is incomplete.
    • Add codecov environment for publishing to Codecov.
  • travis.yml:
    • Publish to Codecov after each environment is run and let Codecov do the combine itself
      • A failed run doesn't prevent publishing any results
      • Codecov reports status faster
  • .coveragerc is now coverage.conf:
    • Add [report] section, now that reports are generated in the Tox config
  • .gitignore:
    • Remove some ignores that shouldn't be needed, since Tox puts things in .tox
    • ✓ Use fixed paths for items that only exist in a fixed path

 * Use absolute paths for fixed locations.
 * Sort
 * Remove items that should be nested into .tox/ now.
Add [report] section.
 * twistedchecker-diff shouldn't be in default envlist, as it only works in CI.
 * "trial" envs now just run trial.  "coverage" envs run trial under coverage.
 * Clean up coverage runs so that we aren't littering the source tree with a bunch of .coverage.* files.
 * Add coverage_combine env which gathers coverage from other runs and reports on the total result.
 * Add codecov env to publish to codecov.

Change Travis config:
 * Use "coverage" envs.
 * Publish to codecov after each test run, instead of one combined publish if they all succeed.
@wsanchez wsanchez mentioned this pull request Jun 21, 2017
@codecov
Copy link

codecov bot commented Jun 21, 2017

Codecov Report

Merging #187 into master will decrease coverage by 0.04%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #187      +/-   ##
==========================================
- Coverage   95.89%   95.84%   -0.05%     
==========================================
  Files          12       12              
  Lines        1558     1542      -16     
  Branches       86       86              
==========================================
- Hits         1494     1478      -16     
  Misses         52       52              
  Partials       12       12
Impacted Files Coverage Δ
src/klein/test/test_resource.py 96.83% <0%> (-0.07%) ⬇️
src/klein/app.py 98.55% <0%> (-0.02%) ⬇️
src/klein/__init__.py 100% <0%> (ø) ⬆️

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 dba85f8...a73859b. Read the comment docs.

@wsanchez
Copy link
Member Author

Ready for review.

Copy link
Member

@glyph glyph left a comment

Choose a reason for hiding this comment

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

I don't really understand the intent of these changes. I've made a couple of notes, but could you just write up a brief description about the intended structure here?

tox.ini Outdated
trial-py{27,py,34,35,36}-tw{155,166,current,trunk}
coverage-py{27,py,34,35,36}-tw{155,166,current,trunk}

coverage_combine
Copy link
Member

Choose a reason for hiding this comment

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

Including this in the envlist is bad because that means it gets run in some random order in both tox with no arguments and detox with no arguments (where it's actively harmful). You can still run it with tox -e without putting it in the envlist.

Copy link
Member Author

@wsanchez wsanchez Jun 28, 2017

Choose a reason for hiding this comment

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

Really? When I run tox with no arguments, it always runs them in a fixed order, and combine runs last. I haven't noticed this randomization…

Copy link
Member Author

Choose a reason for hiding this comment

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

@glyph: Yeah, it runs strictly in the intended order. Are you sure it's random for you?

Copy link
Member

Choose a reason for hiding this comment

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

OK, I didn't realize tox actually ran the environments in order. Nevertheless, detox runs them all at the same time, so this is still a bad idea ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed in 657da86

tox.ini Outdated

docs, docs-linkcheck

skip_missing_interpreters = True


##
# Default testenv
# Build (default environment)
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 understand this comment change. Arguably the comment should just be deleted since it doesn't say much, but this is not a "build" now, is it? it's still a test env. Builds are done with setup.py wheel.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed in 77390bb

tox.ini Outdated
coverage: coverage


whitelist_externals =
Copy link
Member

Choose a reason for hiding this comment

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

This is a bad idea because it makes the tests hard to run on Windows.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed in 7aac72d and 862acc5

tox.ini Outdated

passenv =
PATH
LANG LC_ALL
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need to do localized testing? What is the purpose of passing LANG?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hold over from another thing, removing

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed in f02c021

tox.ini Outdated
coverage: COVERAGE_FILE={toxworkdir}/coverage/coverage.{envname}
{coverage_combine,codecov}: COVERAGE_FILE={toxworkdir}/coverage/coverage

{coverage,coverage_combine}: COVERAGE_HTML={envlogdir}/coverage_report_html
Copy link
Member

Choose a reason for hiding this comment

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

should this be .html rather than _html?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it's a directory name

tox.ini Outdated
coverage: cp "{env:COVERAGE_FILE}" "{envlogdir}/coverage"

# Run coverage reports, ignore exit status
coverage: - coverage html --rcfile="{toxinidir}/.coveragerc" -d "{env:COVERAGE_HTML}"
Copy link
Member

Choose a reason for hiding this comment

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

Coverage reporting is really slow, and should almost always be done only after a coverage combine. definitely we shouldn't be generating both HTML and XML reports on every travis run, where they're just going to be thrown away.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hrm. It takes pretty consistently a bit under 0.4s on my laptop to run coverage html and alittle over 0.4s to run coverage xml.

The reason it's don't done here after a combine is to make it easy to check coverage for each run separately. With Klein that doesn't very much (at all, last I checked), so that's not a big deal.

It'll be easy enough to make it separate, so I'll do that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in 6bcccb1

tox.ini Outdated
coverage combine --append

# Copy aside coverage data for each test environment in case we want to look at it later
cp "{env:COVERAGE_FILE}" "{envlogdir}/coverage"
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this just copy the coverage file from the coverage_combine environment? i.e. nothing?

Copy link
Member Author

Choose a reason for hiding this comment

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

When you run coverage_combine, the source files are deleted. This sets them aside in case you need to look at the coverage for a specific run after having run coverage_combine (eg. tox with no arguments). It's not critical, though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed in 7aac72d

tox.ini Outdated

# Generate XML and publish to codecov.io
# Ignore errors generating coverage XML, which may be due to < 100% coverage; we still want to publish
- coverage xml --rcfile="{toxinidir}/.coveragerc" -o "{env:COVERAGE_XML}"
Copy link
Member

Choose a reason for hiding this comment

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

Why does this line start with a dash but the next one doesn't?

Copy link
Member Author

Choose a reason for hiding this comment

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

This prevents tox from erroring out if this exits with an error due to insufficient coverage; we still want to proceed to invoking codecov (the next line) in that case.

Copy link
Contributor

@moshez moshez left a comment

Choose a reason for hiding this comment

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

I see @glyph already asked for changes, so I just added a few more notes.

.gitignore Outdated
@@ -1,11 +1,7 @@
*.pyc
_trial_temp
Copy link
Contributor

Choose a reason for hiding this comment

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

It's hard to tell which parts of this diff are spurious and which are actual change. can you keep the old order?

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, it's not that big a file, and I don't think it helped that much, but re-ordered.

Copy link
Member Author

Choose a reason for hiding this comment

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

Reordered in 3e7d556

tox.ini Outdated
trial: trial --random=0 --logfile="{envlogdir}/trial.log" --temp-directory="{envlogdir}/trial.d" {posargs:klein}

coverage: mkdir -p "{toxworkdir}/coverage"
coverage: coverage run --rcfile="{toxinidir}/.coveragerc" "{envdir}/bin/trial" --random=0 --logfile="{envlogdir}/trial.log" --temp-directory="{envlogdir}/trial.d" {posargs:klein}
Copy link
Contributor

Choose a reason for hiding this comment

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

If you're explicitly passing in --rcfile, I see no reason to name the file ".coveragerc" and thus make it harder to find.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's just what the file has always been called. I don't have any trouble finding it, but I'm happy to rename it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed in d44dc11

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I should have replied initially:

.coveragerc is the official / standard name of this file - see the docs at http://coverage.readthedocs.io/en/coverage-4.4.1/config.html . coverage.conf is some random thing we just made up. I would much rather not rename it.

tox.ini Outdated
- coverage xml --rcfile="{toxinidir}/.coveragerc" -o "{env:COVERAGE_XML}"

# Don't ignore exit status here; this is our failure status if coverage is insufficient.
coverage report --rcfile="{toxinidir}/.coveragerc" --omit "*/test/*"
Copy link
Contributor

Choose a reason for hiding this comment

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

I usually prefer to put the --fail-under here, so it's more obvious what conditions we use for failure.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I buy that.

This has a side effect I somehow didn't consider, which is that I don't need to ignore exit status so much in the tox file.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in bc03700

@wsanchez
Copy link
Member Author

Ready for review again.

@glyph: Summary of changes posted at the top; sorry I didn't do that at the outset.

tox.ini Outdated

passenv =
PATH
CI CONTINUOUS_INTEGRATION
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see anything in this changeset which references these. Are they for Hypothesis in #181?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah

@wsanchez
Copy link
Member Author

Lemme break this into parts…

@wsanchez wsanchez closed this Dec 14, 2017
@wsanchez wsanchez deleted the coverage branch December 14, 2017 22:51
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.

4 participants