Skip to content

Commit

Permalink
ci: Don't remove .coverage file & set empty suffix.
Browse files Browse the repository at this point in the history
Fixes zulip#14962
* codecov needs `.coverage` file in the pwd to upload coverage
results.
* concurrency='multiprocessing' forces `.coverage` file to have a
data_suffix, we explicity set it to "" for the file to have no suffix.
Filed issue as nedbat/coveragepy#989
  • Loading branch information
amanagr committed May 26, 2020
1 parent 117677d commit f501c14
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ aliases:
run:
name: upload coverage report
command: |
# codecov requires `.coverage` file to be stored in pwd for
# uploading coverage results.
mv /home/circleci/zulip/var/.coverage /home/circleci/zulip/.coverage
. /srv/zulip-py3-venv/bin/activate
# codecov version is fixed here, since future versions of it
# use "find" for locating files which is buggy on some platforms.
Expand Down
2 changes: 1 addition & 1 deletion tools/ci/backend
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set -x
# docker setup means the auto-detection logic sees the ~36 processes
# the Docker host has, not the ~2 processes of resources we're
# allocated.
./tools/test-backend --coverage --include-webhooks --parallel=6
./tools/test-backend --coverage --include-webhooks --no-cov-cleanup --parallel=6

# We run mypy after the backend tests so we get output from the
# backend tests, which tend to uncover more serious problems, first.
Expand Down
13 changes: 9 additions & 4 deletions tools/test-backend
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ def main() -> None:
parser.add_argument('--verbose-coverage', dest='verbose_coverage',
action="store_true",
default=False, help='Enable verbose print of coverage report.')
parser.add_argument('--no-cov-cleanup', dest='no_cov_cleanup',
action='store_true',
default=False,
help="Do not clean generated coverage files.")

parser.add_argument('--parallel', dest='processes',
type=int,
Expand Down Expand Up @@ -354,10 +358,12 @@ def main() -> None:
assert_provisioning_status_ok(options.force)

if options.coverage:
import atexit
import coverage
cov = coverage.Coverage(config_file="tools/coveragerc", concurrency='multiprocessing')
atexit.register(lambda: cov.erase()) # Ensure the data file gets cleaned up at the end.
cov = coverage.Coverage(data_suffix="", config_file="tools/coveragerc", concurrency='multiprocessing')
# Do not clean .coverage file in CircleCi job so that coverage data can be uploaded.
if not options.no_cov_cleanup:
import atexit
atexit.register(lambda: cov.erase()) # Ensure the data file gets cleaned up at the end.
cov.start()
if options.profile:
import cProfile
Expand Down Expand Up @@ -407,7 +413,6 @@ def main() -> None:
cov.stop()
cov.save()
cov.combine()
cov.data_suffix = False # Disable suffix so that filename is .coverage
cov.save()
if options.verbose_coverage:
print("Printing coverage data")
Expand Down

0 comments on commit f501c14

Please sign in to comment.