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

DM-11725: Initial attempt at pytest coverage testing #35

Merged
merged 5 commits into from Jun 6, 2018

Conversation

timj
Copy link
Member

@timj timj commented Aug 31, 2017

No description provided.

Copy link
Contributor

@parejkoj parejkoj left a comment

Choose a reason for hiding this comment

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

See comments.

I ran this on my current jointcal branch, and it does work: the default summary table is nice, though it appears above any pytest errors/warnings (which is maybe a good thing?). It also tells the user where the html and xml files go, which is good.

It would be very nice to include C++ coverage with this, but that's work for a future ticket, since it appears to be nontrivial to accomplish.

@@ -293,3 +305,38 @@ def junitPrefix(self):
prefix += ".{0}".format(os.environ[controlVar])

return prefix

def _pytestCoverage(self, prefix="pytest"):
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rename this method _getPytestCoverageCommand or similar, to clarify what it does.

It should also have a Returns block.

# Use a prefix for the HTML if the prefix is not the default
htmlfile = ""
if prefix != "pytest":
htmlfile = ":'htmlcov-{}'".format(prefix)
Copy link
Contributor

Choose a reason for hiding this comment

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

This puts the output in the package root directory: ./htmlcov: can we get it put into the tests/ directory, or maybe in doc/? The xml report is written to tests/.tests/pytest-cov-*.xml, so tests/.tests/htmlcov seems like a good place.

We also need to add it to the .gitignore and as a scons --clean target.


def _pytestCoverage(self, prefix="pytest"):
"""Form the additional arguments required to enable coverage testing.
Prefix is used to form the output files.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this docstring needs to breakdown what the various possibilities for prefix do. I'm having trouble parsing it from the code itself.

If the goal is to just turn on or off html and xml output, why not just have explicit options for those (terminal=True, html=True, xml=False seems like a sensible default), and then Jenkins or whatever can configure that as part of run().

Copy link
Member Author

Choose a reason for hiding this comment

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

The prefix really is the prefix to use for the output files, since each pytest invocation needs to have different output files. I think I can remove prefix if I use Scons ${TARGET} instead. If I do that I solve your problem of writing the files in .tests but they get directory names like tests/.tests/pytest-utils.xml-htmlcov (for utils). If people don't mind the extra .xml in there then the code is much much simpler.


# if we have a standard package layout, restrict coverage to the
# python code and do not include the tests.
if os.path.exists("python") or os.path.exists(os.path.join(os.path.pardir, "python")):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why these two? Could you instead just use eups.packagedir() here to take care of both cases?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've changed it to always use . and include coverage of tests.

options += " --cov=python"
else:
# Default to coverage for everything in this directory and below
options += " --cov=."
Copy link
Contributor

Choose a reason for hiding this comment

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

What packages do we have that would end up in this branch?

Copy link
Member Author

Choose a reason for hiding this comment

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

I can't remember why I needed that. I'm using --cov=. for everything now.

timj added 3 commits June 5, 2018 14:05
* Always use ${TARGET}
* Always do coverage relative to root directory.
They are the same each time now and printing multiple identical
copies is not helpful.
@timj
Copy link
Member Author

timj commented Jun 5, 2018

I've made all the requested changes. The coverage files are now always written into the tests/.tests directory.

@timj timj merged commit d93e90d into master Jun 6, 2018
@ktlim ktlim deleted the tickets/DM-11725 branch August 25, 2018 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants