feat: add comprehensive testing infrastructure with pytest - #129
Conversation
- Add pytest, pytest-cov, and pytest-mock as dev dependencies - Configure pytest with custom markers (unit, integration, slow) - Set up coverage reporting with HTML and XML output - Create test directory structure for both cli and lib packages - Add shared fixtures in conftest.py for common test scenarios - Update .gitignore with testing and Claude-related entries - Add Poetry script commands for running tests - Include validation tests to verify infrastructure setup
|
@Libbl, thank you for the submission! I'm on vacation now, and I'll review this in July. A better test infrastructure will help us to maintain the project and have confidence that everything still works as it should. |
|
Hey, you’re welcome. Let me know if you want a more unified testing approach and see if I can get it set up at the project root instead. |
|
@llbbl , I'm sorry I didn't get back to you sooner. My vacation was actually parental leave. I became a dad 1 month before you submitted this pull request and since then my time for open source work dropped to zero. Found a moment to look at it again. I'll run your instructions and provide feedback. |
|
I ran the tests. They all pass! But the coverage report failed: Here's the full output. Have I missed a step? Is there a missing dependency? I also get an error when I try to open the coverage report: It's missing. A minor issue: The first run of |
|
@llbbl , I realize it's been a long time, and you might have moved on to something else. If you're still able to contribute, I'd appreciate your advice to solve the problem with the code coverage report. |
|
(i think) It's this part here in the poetry file: fail_under = 80 The template that I was using to setup the poetry file had that set. It's saying fail test coverage if coverage is less than 80%. And because this pull request is just setting up unit testing, we don't have any test coverage. simple fix is comment out for now. |
fixing test coverage for now. don't forget to add back later.
Add Comprehensive Testing Infrastructure
Summary
This PR establishes a complete testing infrastructure for the aws-sso-util project using pytest and Poetry. The setup provides a foundation for writing unit tests, integration tests, and maintaining code coverage standards.
Changes Made
Testing Dependencies
pytest(^7.4.0) - Core testing frameworkpytest-cov(^4.1.0) - Coverage reporting pluginpytest-mock(^3.11.1) - Mocking utilitiesConfiguration
pytest configuration in
pyproject.toml:test_*.pyand*_test.pyfilesunit,integration, andslowCoverage configuration:
aws_sso_utilandaws_sso_lib__init__.py, and vendored codehtmlcov/directoryDirectory Structure
Shared Fixtures
Both
conftest.pyfiles provide common fixtures including:temp_dir- Temporary directory managementmock_aws_config_dir/mock_aws_config- AWS configuration mockingmock_sso_cache_dir/mock_sso_cache- SSO cache mockingmock_boto3_client/mock_boto3_session- AWS API mockingmock_environment- Environment variable mockingsample_yaml_config/sample_sso_token- Test data fixturesmock_click_context- CLI testing utilitiescapture_logs/capture_stdout- Output capture fixturesPoetry Commands
poetry run test- Run all tests with coveragepoetry run tests- Alternative command (both work)Updated Files
.gitignore- Added testing artifacts and Claude directories[tool.poetry.dev-dependencies]to[tool.poetry.group.dev.dependencies]How to Use
Install dependencies:
Run tests:
View coverage report:
# HTML report will be in htmlcov/index.html open htmlcov/index.htmlNext Steps
With this infrastructure in place, developers can now:
Notes
test_setup_validation.py) verify the infrastructure is working correctlypyproject.toml