Skip to content

Commit

Permalink
Upload test coverage to SonarCloud
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-Christophe Morin <[email protected]>
  • Loading branch information
JeanChristopheMorinPerso committed Mar 1, 2024
1 parent 8d56142 commit 481a637
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
4 changes: 3 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[run]
# Relative is needed for coverage to be merged by SonarCloud
relative_files = True
branch = True
omit =
src/rez/tests/*,
src/rez/completion/*,
src/rez/vendor/*
src/rez/vendor/*
10 changes: 9 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ jobs:
run: rez-python -m pip install pytest-cov parameterized

- name: Run tests
run: rez-selftest -v
run: rez-selftest -v -- --cov=rez --cov-report=xml:coverage.xml
env:
_REZ_ENSURE_TEST_SHELLS: ${{ matrix.shells }}

- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: -Dsonar.python.coverage.reportPaths=coverage.xml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ build/
dist/
htmlcov/
.coverage
coverage.xml
*~
docs/_build
.DS_Store
Expand Down
3 changes: 1 addition & 2 deletions .sonarcloud.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ sonar.projectName=rez

# Source properties
sonar.sources=src
sonar.exclusions=src/build_utils/**,src/rez/backport/**,src/rez/data/**,src/rez/tests/**,src/rez/vendor/**

sonar.exclusions=src/build_utils/**,src/rez/data/**,src/rez/tests/**,src/rez/vendor/**
2 changes: 0 additions & 2 deletions pytest.ini

This file was deleted.

15 changes: 6 additions & 9 deletions src/rez/cli/selftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,8 @@ def command(opts, parser, extra_arg_groups=None):

try:
if use_pytest:
cwd = os.getcwd()
os.chdir(tests_dir)
try:
run_pytest(module_tests, opts.tests, opts.verbose,
extra_arg_groups)
finally:
os.chdir(cwd)
run_pytest(module_tests, opts.tests, opts.verbose,
extra_arg_groups)

else:
run_unittest(module_tests, opts.tests, opts.verbose)
Expand All @@ -121,6 +116,8 @@ def run_unittest(module_tests, tests, verbosity):
def run_pytest(module_tests, tests, verbosity, extra_arg_groups):
from pytest import main

tests_dir = os.path.abspath(os.path.join(__file__, "..", "..", "tests"))

# parse test name, e.g.
# "rez.tests.test_solver.TestSolver.test_01"
# into
Expand All @@ -133,11 +130,11 @@ def run_pytest(module_tests, tests, verbosity, extra_arg_groups):
specifier += "::" + part
continue
if os.path.isfile(part + ".py"):
specifier = part + ".py"
specifier = os.path.join(tests_dir, f"{part}.py")
if specifier:
test_specifications.append(specifier)

module_tests = [("test_%s.py" % x) for x in sorted(module_tests)]
module_tests = [os.path.join(tests_dir, f"test_{x}.py") for x in sorted(module_tests)]
tests = module_tests + test_specifications

argv = tests[:]
Expand Down

0 comments on commit 481a637

Please sign in to comment.