chore: Migrate test infrastructure to pytest - #134
Merged
Conversation
- Replace unittest2 (Python 2 backport) with pytest - Replace coverage with pytest-cov - Remove mock dependency (built into Python 3.3+) - Add pytest configuration to pyproject.toml - Update CI workflow to use pytest - Update CONTRIBUTING.MD with pytest commands - Mark functional tests to skip when RAYGUN_API_KEY not set - Refactor global variable tests to use direct injection instead of relying on module globals (fixes pytest compatibility)
There was a problem hiding this comment.
Pull request overview
This PR modernizes the test infrastructure by migrating from unittest to pytest, removing legacy Python 2 dependencies (unittest2, mock) that are no longer needed, and updating CI workflows accordingly.
Changes:
- Replaced
unittest2,mock, andcoveragedependencies withpytestandpytest-cov - Updated CI workflow to use pytest commands for running tests and generating coverage reports
- Refactored functional tests to use
@pytest.mark.skipifdecorator instead of raising errors insetUp - Refactored global variable payload size tests to directly inject test data instead of relying on module globals
- Fixed typo in test method name (
test_remove_larger_varaible→test_remove_larger_variable)
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
pyproject.toml |
Replaced legacy test dependencies with pytest and pytest-cov; added pytest configuration |
.github/workflows/python-checks.yml |
Updated CI commands to use pytest with coverage integration |
python3/tests/test_functional.py |
Added pytest skip decorator for tests requiring API key |
python3/tests/test_raygunmsgs.py |
Refactored global variable tests to inject data directly; fixed method name typo |
CONTRIBUTING.MD |
Updated documentation with new pytest test commands |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The standalone mock package was removed as a dependency since it's built into Python 3.3+. Updated remaining test files that were still using the external import.
miquelbeltran
approved these changes
Jan 19, 2026
ProRedCat
approved these changes
Jan 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description 📝
Purpose:
Modernize the test infrastructure by migrating from
unittesttopytest, and remove legacy Python 2 testing dependencies that are no longer needed.Background - Why pytest over unittest?
The codebase was using Python's built-in
unittestmodule along with two legacy dependencies:unittest2- A backport of Python 2.7's unittest improvements to Python 2.6. This library has been completely unnecessary since Python 3.0 (released in 2008) and was never being imported anywhere in the codebase—it was a dead dependency.mock- A standalone mocking library that was merged into Python's standard library asunittest.mockin Python 3.3 (2012). Since raygun4py requires Python 3.9+, this external dependency is redundant.Why pytest is the better choice:
self.assertEqual(a, b)assert a == bsetUp/tearDownmethodsTestCasetest_*.pyfunction or class workssubTestor manual loops@pytest.mark.parametrizedecoratorself.prefix everywherecoveragepackagepytest-covImportant compatibility note: pytest can run existing
unittest.TestCaseclasses without modification. This means we get all the benefits of pytest without rewriting every test—the existing test classes continue to work as-is.Approach:
Replaced dependencies in
pyproject.toml:unittest2>=1.1.0(dead dependency, never imported)mock>=2.0.0(built into Python 3.3+ asunittest.mock)coverage(replaced by pytest-cov integration)pytest>=7.0pytest-cov>=4.0Added pytest configuration to
pyproject.toml:Updated CI workflow to use pytest:
coverage run --source=python3 -m unittest discover python3/testspytest --cov=python3/raygun4py --cov-report=term-missingUpdated functional tests to skip gracefully when
RAYGUN_API_KEYis not set (instead of raising an error in setUp).Refactored global variable tests - Two tests (
test_remove_global_too_largeandtest_remove_larger_variable) were testing payload size limiting for global variables. These tests relied on capturing actual module globals, which doesn't work reliably in pytest's test environment. Refactored them to directly inject controlled test data into theRaygunErrorMessage.globalVariablesattribute, making them deterministic and runner-agnostic.Updated CONTRIBUTING.MD with new test commands.
Type of change
chore:Chore task, release or small impact changeci:CI configuration changeUpdates
unittest2,mock, andcoveragewithpytestandpytest-cov[tool.pytest.ini_options]configuration topyproject.toml.github/workflows/python-checks.ymlto use pytestCONTRIBUTING.MDwith pytest commandstest_functional.pyto use@pytest.mark.skipiffor missing API keytest_raygunmsgs.pyglobal variable tests for pytest compatibilitytest_remove_larger_varaible→test_remove_larger_variableRelated issues
Closes #125
Test plan 🧪
All 93 tests pass with pytest:
RAYGUN_API_KEYis set, skipped otherwise)Author to check 👓
Reviewer to check ✔️