Skip to content

Conversation

@marcelofern
Copy link
Contributor

This PR makes it so codecoverage also runs in the tests/ folder.

Similar to the src/ folder, the tests/ folder can also have dead paths
or misconfiguration in test functions or fixtures that may lead to dead
tests, or false assumptions about what is being tested.

This change will start looking for lack of coverage on files in the
tests/ folder, and should help with finding out what these tests are in
the future.
This commit addresses the lines where codecoverage didn't hit in the
test_timeouts.py file.

The _Leaky class is designed to never hit certain code paths, and
because of that codecoverage will complain. This is expected, however,
and codecoverage can be ignored in these cases.

As for tests containing context managers like this:

  with pytest.raises(...):
      with timeouts.apply_timeouts(
          using="default",
          lock_timeout=lock_timeout,
          statement_timeout=statement_timeout,
      ):
          # This line will never be hit, because the context manager
          # raises before it can run.
          pass

An alternative would be to call __enter__() manually:

  timeouts.apply_timeouts(
      using="default",
      lock_timeout=lock_timeout,
      statement_timeout=statement_timeout,
  ).__enter__()

But that looks a bit unergonomic, and isn't the way this is used in
practice. Instead, a # pragma: no cover was slapped on it.
@github-actions
Copy link

github-actions bot commented Apr 4, 2025

Coverage Report Results

Name Stmts Miss Branch BrPart Cover
src/django_pg_migration_tools/indexes.py 9 0 0 0 100%
src/django_pg_migration_tools/management/commands/migrate_with_timeouts.py 138 0 20 0 100%
src/django_pg_migration_tools/operations.py 453 0 90 0 100%
src/django_pg_migration_tools/timeouts.py 73 0 30 0 100%
tests/django_pg_migration_tools/management/commands/test_migrate_with_timeouts.py 126 0 0 0 100%
tests/django_pg_migration_tools/test_indexes.py 33 0 0 0 100%
tests/django_pg_migration_tools/test_operations.py 1640 0 0 0 100%
tests/django_pg_migration_tools/test_package.py 3 0 0 0 100%
tests/django_pg_migration_tools/test_timeouts.py 75 0 0 0 100%
TOTAL 2550 0 140 0 100%

6 empty files skipped.

@marcelofern marcelofern requested a review from a team April 4, 2025 02:50
@marcelofern marcelofern changed the title Add coverage for test paths Run coverage against test folder Apr 4, 2025
Copy link
Contributor

@timb07 timb07 left a comment

Choose a reason for hiding this comment

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

LGTM

@marcelofern marcelofern merged commit fb938d3 into main Apr 6, 2025
11 checks passed
@marcelofern marcelofern deleted the add-coverage-for-test-paths branch April 6, 2025 22:01
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.

3 participants