Skip to content

Commit d589bfc

Browse files
authored
Move coverage configuration to pyproject.toml (#7038)
* Copy configuration from dev_tools/conf/.coveragerc to pyproject.toml Configuration verified by comparing output from `coverage debug --rcfile=dev_tools/conf/.coveragerc config` and `coverage debug config` Partially fixes #6800 * Delete `dev_tools/conf/.coveragerc` and its references The coverage configuration is now present in pyproject.toml by default. * Introduce temporary TYPE_CHECKING guarded import * Revert "Introduce temporary TYPE_CHECKING guarded import" This reverts commit ef248ea.
1 parent dee2c5c commit d589bfc

5 files changed

Lines changed: 26 additions & 33 deletions

File tree

check/pytest-and-incremental-coverage

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ fi
7171
source dev_tools/pypath || exit $?
7272

7373
# Run tests while producing coverage files.
74-
check/pytest --cov \
75-
--cov-config=dev_tools/conf/.coveragerc \
76-
"${PYTEST_ARGS[@]}"
74+
check/pytest --cov "${PYTEST_ARGS[@]}"
7775
pytest_result=$?
7876

7977

check/pytest-changed-files-and-incremental-coverage

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ source dev_tools/pypath || exit $?
9292
# Run tests while producing coverage files.
9393
check/pytest "${changed_python_tests[@]}" \
9494
"${cov_changed_python_file_dirs[@]}" \
95-
--cov-report=annotate \
96-
--cov-config=dev_tools/conf/.coveragerc
95+
--cov-report=annotate
9796
pytest_result=$?
9897

9998
# Analyze coverage files.

dev_tools/bash_scripts_test.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,7 @@ def test_pytest_and_incremental_coverage_branch_selection(tmpdir_factory):
344344
)
345345
assert result.returncode == 0
346346
assert result.stdout == (
347-
'INTERCEPTED check/pytest '
348-
'--cov --cov-config=dev_tools/conf/.coveragerc\n'
347+
'INTERCEPTED check/pytest --cov\n'
349348
'No data to report.\n'
350349
'INTERCEPTED '
351350
'python dev_tools/check_incremental_coverage_annotations.py HEAD\n'
@@ -368,8 +367,7 @@ def test_pytest_and_incremental_coverage_branch_selection(tmpdir_factory):
368367
)
369368
assert result.returncode == 0
370369
assert result.stdout == (
371-
'INTERCEPTED check/pytest '
372-
'--cov --cov-config=dev_tools/conf/.coveragerc\n'
370+
'INTERCEPTED check/pytest --cov\n'
373371
'No data to report.\n'
374372
'INTERCEPTED '
375373
'python dev_tools/check_incremental_coverage_annotations.py main\n'
@@ -384,8 +382,7 @@ def test_pytest_and_incremental_coverage_branch_selection(tmpdir_factory):
384382
)
385383
assert result.returncode == 0
386384
assert result.stdout == (
387-
'INTERCEPTED check/pytest '
388-
'--cov --cov-config=dev_tools/conf/.coveragerc\n'
385+
'INTERCEPTED check/pytest --cov\n'
389386
'No data to report.\n'
390387
'INTERCEPTED '
391388
'python dev_tools/check_incremental_coverage_annotations.py origin/main\n'
@@ -400,8 +397,7 @@ def test_pytest_and_incremental_coverage_branch_selection(tmpdir_factory):
400397
)
401398
assert result.returncode == 0
402399
assert result.stdout == (
403-
'INTERCEPTED check/pytest '
404-
'--cov --cov-config=dev_tools/conf/.coveragerc\n'
400+
'INTERCEPTED check/pytest --cov\n'
405401
'No data to report.\n'
406402
'INTERCEPTED '
407403
'python dev_tools/check_incremental_coverage_annotations.py upstream/main\n'
@@ -416,8 +412,7 @@ def test_pytest_and_incremental_coverage_branch_selection(tmpdir_factory):
416412
)
417413
assert result.returncode == 0
418414
assert result.stdout == (
419-
'INTERCEPTED check/pytest '
420-
'--cov --cov-config=dev_tools/conf/.coveragerc\n'
415+
'INTERCEPTED check/pytest --cov\n'
421416
'No data to report.\n'
422417
'INTERCEPTED '
423418
'python dev_tools/check_incremental_coverage_annotations.py upstream/main\n'
@@ -444,8 +439,7 @@ def test_pytest_and_incremental_coverage_branch_selection(tmpdir_factory):
444439
)
445440
assert result.returncode == 0
446441
assert result.stdout == (
447-
'INTERCEPTED check/pytest '
448-
'--cov --cov-config=dev_tools/conf/.coveragerc\n'
442+
'INTERCEPTED check/pytest --cov\n'
449443
'No data to report.\n'
450444
'INTERCEPTED '
451445
'python dev_tools/check_incremental_coverage_annotations.py HEAD\n'
@@ -460,8 +454,7 @@ def test_pytest_and_incremental_coverage_branch_selection(tmpdir_factory):
460454
)
461455
assert result.returncode == 0
462456
assert result.stdout == (
463-
'INTERCEPTED check/pytest '
464-
'--cov --cov-config=dev_tools/conf/.coveragerc\n'
457+
'INTERCEPTED check/pytest --cov\n'
465458
'No data to report.\n'
466459
'INTERCEPTED '
467460
'python dev_tools/check_incremental_coverage_annotations.py main\n'
@@ -483,8 +476,7 @@ def test_pytest_and_incremental_coverage_branch_selection(tmpdir_factory):
483476
)
484477
assert result.returncode == 0
485478
assert result.stdout.startswith(
486-
'INTERCEPTED check/pytest '
487-
'--cov --cov-config=dev_tools/conf/.coveragerc\n'
479+
'INTERCEPTED check/pytest --cov\n'
488480
'No data to report.\n'
489481
'INTERCEPTED '
490482
'python dev_tools/check_incremental_coverage_annotations.py '

dev_tools/conf/.coveragerc

Lines changed: 0 additions & 12 deletions
This file was deleted.

pyproject.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@ target_version = ['py310', 'py311', 'py312']
44
skip-string-normalization = true
55
skip-magic-trailing-comma = true
66

7+
8+
[tool.coverage.run]
9+
include = [
10+
# Omit files outside the current working directory.
11+
# Note: this means coverage must be run from the cirq repo root.
12+
# Failure to do so will result in false positives.
13+
"./*",
14+
]
15+
omit = ["benchmarks/*"]
16+
17+
[tool.coverage.report]
18+
exclude_also = [
19+
"if TYPE_CHECKING:",
20+
]
21+
22+
723
[tool.pytest.ini_options]
824
filterwarnings = [
925
"ignore:Matplotlib is currently using agg:UserWarning",

0 commit comments

Comments
 (0)