Repository navigation
test: standardize tests from unittest to pytest - #41
Conversation
There was a problem hiding this comment.
Pull request overview
This PR standardizes test files from the unittest framework to pytest, modernizing the testing infrastructure for improved functionality and alignment with contemporary Python testing practices. The conversion affects 35+ test files across the repository, touching structured object evaluator tests, common utility tests, and comparator tests.
Key Changes:
- Converted all test classes from unittest.TestCase inheritance to plain pytest classes
- Replaced unittest assertion methods with native Python assert statements
- Migrated setUp() lifecycle methods to pytest's setup_method()
- Added pytest configuration in pyproject.toml with test discovery and default options
Reviewed changes
Copilot reviewed 39 out of 39 changed files in this pull request and generated 18 comments.
Show a summary per file
| File | Description |
|---|---|
| pyproject.toml | Added pytest configuration section with test paths and options |
| tests/structured_object_evaluator/*.py (30 files) | Converted from unittest to pytest patterns: class inheritance, assertions, setup methods |
| tests/common/*.py (5 files) | Migrated utility and evaluator tests to pytest framework |
| tests/common/comparators/*.py (7 files) | Converted comparator tests with proper mock handling |
| tests/common/algorithms/test_hungarian.py | Migrated algorithm tests to pytest with proper approx usage |
The migration appears comprehensive and well-executed. All test files follow consistent pytest patterns, with proper conversion of assertions, lifecycle methods, and decorators. The removal of if __name__ == "__main__": unittest.main() blocks is appropriate for pytest-based test discovery.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| score = self.comparator.compare("Hello", "hello") | ||
| if score < 1.0: | ||
| self.assertLess(score, 1.0) # Should be case sensitive | ||
| assert score < 1.0 # Should be case sensitive |
There was a problem hiding this comment.
Test is always true, because of this condition.
| assert score < 1.0 # Should be case sensitive | |
| # Should be case sensitive |
| """Tests for the anls_score utility functions.""" | ||
|
|
||
| import unittest | ||
| import pytest |
There was a problem hiding this comment.
Import of 'pytest' is not used.
| import pytest |
| """Unit tests for the BaseComparator class.""" | ||
|
|
||
| import unittest | ||
| import pytest |
There was a problem hiding this comment.
Import of 'pytest' is not used.
| import pytest |
| """ | ||
|
|
||
| import unittest | ||
| import pytest |
There was a problem hiding this comment.
Import of 'pytest' is not used.
| import pytest |
| """Tests for edge cases in the structured object evaluator.""" | ||
|
|
||
| import unittest | ||
| import pytest |
There was a problem hiding this comment.
Import of 'pytest' is not used.
| import pytest |
| """Test integration of structured models with the main anls_score function.""" | ||
|
|
||
| import unittest | ||
| import pytest |
There was a problem hiding this comment.
Import of 'pytest' is not used.
| """Tests for structured model comparison using the new StructuredModel implementation.""" | ||
|
|
||
| import unittest | ||
| import pytest |
There was a problem hiding this comment.
Import of 'pytest' is not used.
| """ | ||
|
|
||
| import unittest | ||
| import pytest |
There was a problem hiding this comment.
Import of 'pytest' is not used.
| import unittest | ||
| import pytest | ||
| from typing import List | ||
| from unittest.mock import patch |
There was a problem hiding this comment.
Import of 'patch' is not used.
| """ | ||
|
|
||
| import unittest | ||
| import pytest |
There was a problem hiding this comment.
Import of 'pytest' is not used.
🔒 Security Scan ResultsASH Security Scan Report
Scan Metadata
SummaryScanner ResultsThe table below shows findings by scanner, with status based on severity thresholds and dependencies:
Top 2 HotspotsFiles with the highest number of security findings:
Detailed FindingsShow 2 actionable findingsFinding 1: CKV2_GHA_1
Description: Finding 2: javascript.browser.security.insecure-document-method.insecure-document-method
Description: Code Snippet: Report generated by Automated Security Helper (ASH) at 2025-12-03T05:45:41+00:00 |
🔒 Security Scan ResultsASH Security Scan Report
Scan Metadata
SummaryScanner ResultsThe table below shows findings by scanner, with status based on severity thresholds and dependencies:
Top 2 HotspotsFiles with the highest number of security findings:
Detailed FindingsShow 2 actionable findingsFinding 1: CKV2_GHA_1
Description: Finding 2: javascript.browser.security.insecure-document-method.insecure-document-method
Description: Code Snippet: Report generated by Automated Security Helper (ASH) at 2025-12-03T05:59:29+00:00 |
| requires = ["setuptools >= 61.0", "wheel"] | ||
| build-backend = "setuptools.build_meta" | ||
|
|
||
| [tool.pytest.ini_options] |
There was a problem hiding this comment.
I've also seen this done with a pytest.ini file that we may consider using. The pyproject.toml file can become cluttered with configuration over time if every tool uses it.
There was a problem hiding this comment.
Yep, I think that'd be great too but might pollute the root with more files. Would be good to keep within the pyproject.toml for now but definitely valuable to consider a separate pytest.ini as we add more tools and options
|
Running ruff to lint and format, I'm finding a lot of changes and recommendations - going to open a separate PR afterwards off of |
| score = self.comparator.compare("Hello", "hello") | ||
| if score < 1.0: | ||
| self.assertLess(score, 1.0) # Should be case sensitive | ||
| assert score < 1.0 # Should be case sensitive |
* test: standardize tests from unittest to pytest --------- Co-authored-by: Aditya Addepalli <adiadd@amazon.com>
Issue #, if available:
N/A
Description of changes:
Standardized all test files from unittest to pytest framework for improved test functionality and modern Python testing practices.
Changes include:
pyproject.tomlwith test discovery settingsand default options for verbose output and short tracebacks
unittest.TestCaseinheritance to plain classessetUp()methods with pytest'ssetup_method()assertEqual,assertAlmostEqual, etc.) withnative Python assert statements
pytest.approx()for floating point comparisons instead ofassertAlmostEqual()All tests pass as before:
Potential Future Enhancements:
test_exact.pyandtest_numeric.pycould use@pytest.mark.parametrizeconftest.pyfixtures instead of inline comparator creationBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.