BB-4 - Marking files as critical

Mark files as critical

Now that we know how to customize Codecov with the codecov.yml file, let's take a look at how to manually mark files as critical. Not all files in a codebase are important. Some files or directories may be more critical or change-sensitive. By marking files as critical in Codecov, you can more quickly identify changes in coverage to those files.

Let's start out with a new branch, step4.

git checkout main
git pull
git checkout -b 'step4a'

We can mark api/calculator.py as critical by adding the following to the codecov.yml file.

comment:
  show_critical_paths: true

profiling:
  critical_files_paths:
    - api/calculator.py

In order for api/calculator.py to be marked as a critical file, the codecov.yml file must be merged into the main branch.

git add .
git commit -m 'step4a: add critical file'
git push origin step4a

Merge in the pull request when finished.

View critical files in the Codecov comment

Create a new branch, step4b.

git checkout main
git pull
git checkout -b 'step4b'

Now, let's make a change to api/tests/calculator.py, so we can see the critical label in the Codecov comment. Notice that we are changing the tests and not the actual file itself. The critical label will appear for files that have a coverage change.

In api/tests/calculator.py, remove the test_add function. The file should look like this

from ..calculator import Calculator


def test_subtract():
    assert Calculator.subtract(1, 2) == -1.0
    assert Calculator.subtract(2, 1) == 1.0
    assert Calculator.subtract(1.0, 2.0) == -1.0
    assert Calculator.subtract(0, 2.0) == -2.0
    assert Calculator.subtract(2.0, 0.0) == 2.0
    assert Calculator.subtract(-4, 2.0) == -6.0

def test_multiply():
    assert Calculator.multiply(1, 2) == 2.0
    assert Calculator.multiply(1.0, 2.0) == 2.0
    assert Calculator.multiply(0, 2.0) == 0.0
    assert Calculator.multiply(2.0, 0.0) == 0.0
    assert Calculator.multiply(-4, 2.0) == -8.0

def test_divide():
    assert Calculator.divide(1, 2) == 0.5
    assert Calculator.divide(1.0, 2.0) == 0.5
    assert Calculator.divide(0, 2.0) == 0
    assert Calculator.divide(-4, 2.0) == -2.0

def test_divide_by_0():
    assert Calculator.divide(2.0, 0) == 'Cannot divide by 0'

Now, create a pull request and wait for CI to finish.

git add .
git commit -m 'step4b: remove add function'
git push origin step4b

You should see the Critical file label on api/calculator.py.

491491