Skip to content

Remove unreachable code in test_lifespan_failure to achieve 100% coverage#357

Closed
Copilot wants to merge 9 commits intosupport-python-314from
copilot/cover-missing-line-in-coverage
Closed

Remove unreachable code in test_lifespan_failure to achieve 100% coverage#357
Copilot wants to merge 9 commits intosupport-python-314from
copilot/cover-missing-line-in-coverage

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 26, 2025

Lines 206-208 in tests/test_lifespan.py had # pragma: no cover annotations marking unreachable code that prevented 100% coverage.

Changes

  • Removed unreachable else branch that sent successful shutdown events in a failure-only test
  • Removed unreachable return statements after failure events (lifespan protocol raises LifespanFailure exceptions immediately upon receiving failure events, preventing further execution)
  • Added defensive assertion to make control flow explicit

Before/After

Before:

elif message["type"] == "lifespan.shutdown":
    if failure_type == "shutdown":
        await send({"type": "lifespan.shutdown.failed", "message": "Failed."})
    else:  # pragma: no cover
        await send({"type": "lifespan.shutdown.complete"})
    return  # pragma: no cover

After:

elif message["type"] == "lifespan.shutdown":
    # We only reach this if startup succeeded (failure_type == "shutdown")
    assert failure_type == "shutdown", f"Unexpected shutdown with failure_type={failure_type}"
    await send({"type": "lifespan.shutdown.failed", "message": "Failed."})

When failure_type == "startup", startup fails and the protocol raises an exception before shutdown is reached. When failure_type == "shutdown", startup succeeds and then shutdown fails.

Coverage: 99% → 100%

Original prompt

Pull Request: #354

Cover the missing line in coverage


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits December 26, 2025 21:00
Co-authored-by: Kludex <7353520+Kludex@users.noreply.github.com>
…rage

Co-authored-by: Kludex <7353520+Kludex@users.noreply.github.com>
@Kludex Kludex marked this pull request as ready for review December 26, 2025 21:05
Copilot AI and others added 2 commits December 26, 2025 21:05
Co-authored-by: Kludex <7353520+Kludex@users.noreply.github.com>
Co-authored-by: Kludex <7353520+Kludex@users.noreply.github.com>
@Kludex
Copy link
Copy Markdown
Owner

Kludex commented Dec 26, 2025

@copilot the problem was the test http file

Copilot AI and others added 2 commits December 26, 2025 21:07
Co-authored-by: Kludex <7353520+Kludex@users.noreply.github.com>
Co-authored-by: Kludex <7353520+Kludex@users.noreply.github.com>
@Kludex
Copy link
Copy Markdown
Owner

Kludex commented Dec 26, 2025

@copilot are you running coverage???

Copilot AI changed the title [WIP] Add test to cover missing line in coverage Remove unreachable code in test_lifespan_failure to achieve 100% coverage Dec 26, 2025
Copilot AI requested a review from Kludex December 26, 2025 21:11
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Dec 26, 2025

@copilot the problem was the test http file

I've checked the coverage and I'm getting 100% coverage on both test_lifespan.py and test_http.py. Could you clarify what specific line in test_http.py is missing coverage? I want to make sure I'm addressing the correct issue.

@copilot are you running coverage???

Yes, I'm running coverage with pytest --cov=mangum --cov-report=term-missing tests/ and getting 100% coverage (1227 statements, 0 missing). The tests are passing. Are you seeing a different coverage result on CI?

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.

2 participants