pySCG: Add a testing framework for Python code examples and documentation
Chưa có ai nhận issue này.
- #1011 của @tommcd — đã đóng, không merge
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 20/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- github-actions, python
- Lĩnh vực
- ci-cd, documentation, testing
Hướng nghiên cứu
The issue points to docs/Secure-Coding-Guide-for-Python/tests/, pyproject.toml, tox.ini, and .github/workflows/python-tests.yml; begin with tests/README.md and the existing test results in KNOWN_ISSUES.md. The described framework spans code examples, Markdown checks, link validation, and CI across multiple Python versions. Done means those checks and CI behavior match the listed requirements; the issue notes 44 existing problem files for follow-up.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
Add a pytest-based testing framework to validate Python code examples and Markdown documentation structure across the Secure Coding Guide for Python.
[!NOTE]
We moved repo since creating this source code for this solution is on a closed PR in source
https://github.com/ossf/wg-best-practices-os-developers/pull/1011
Motivation
Currently, there is no automated validation of:
- Python code syntax and deprecation warnings in examples
- Markdown documentation structure conformance to the template
- Internal links and code file references
- Consistency across 100+ CWE articles
This leads to potential issues with broken examples, missing documentation sections, and broken links that could confuse contributors and readers.
Solution
Implement a comprehensive testing framework that validates:
1. Python Code Quality
- Syntax validation using
ast.parse() - Deprecation warning detection via subprocess execution
- Expected output validation against documented examples
- Support for expected failure markers (intentional issues)
- Automatic cleanup of test artifacts
2. Markdown Documentation Structure
- Required sections validation (title, introduction, Non-Compliant, Compliant, Automated Detection, Related Guidelines, Bibliography)
- Code file reference validation (compliant01.py, noncompliant01.py exist)
- Table structure validation (Automated Detection, Related Guidelines, Bibliography)
- Section order validation
3. Link Validation
- Internal link validation in README.md files
- Index table link validation
- Integration with lychee for comprehensive link checking (internal only in CI, external available locally)
4. CI/CD Integration
- GitHub Actions workflow for automated testing on PRs
- Smart testing: Only tests changed CWE directories on PRs (fast, ~1 min)
- Full suite: Runs all tests on pushes to main (~3 min)
- Multi-version testing (Python 3.9-3.14)
- Coverage reporting to Codecov
- Fast execution with uv package manager
5. Local Development Support
- Easy setup with
uv sync --group test - Multi-version testing with tox
- Parallel execution support with pytest-xdist
- Clean issue reporting with
generate_issue_report.py - Comprehensive documentation in tests/README.md
Implementation Details
- Uses pytest with parametrized tests for all Python and Markdown files
- Organized test utilities in
tests/utils/for maintainability - PEP 735 dependency groups for clean dependency management
- Automatic cleanup of test artifacts (database files, temp files, etc.)
- Cross-platform Python-based issue report generator
Benefits
- Ensures all code examples are syntactically valid and run without warnings
- Validates documentation consistency across all CWE articles
- Catches broken links and missing files before merge
- Provides clear, actionable error messages for contributors
- Reduces review burden by automating quality checks
- Supports Python 3.9-3.14 compatibility testing
- Fast CI/CD with smart testing (only changed files on PRs)
Current State
The framework identifies issues in 44 files (documented in KNOWN_ISSUES.md):
- 31 Documentation files with issues:
- Missing required sections (Bibliography, Automated Detection, etc.)
- Missing required tables
- Section order issues
- Missing code file references
- 13 Python code files with issues:
- 11 files with execution timeouts (intentional infinite loops/blocking operations)
- 1 file with DeprecationWarning
- 1 file with output mismatch
These pre-existing issues can be addressed in follow-up PRs. The testing framework will prevent new issues from being introduced.
Files Added/Modified
New Files:
.github/workflows/python-tests.yml- CI/CD workflow with smart testingdocs/Secure-Coding-Guide-for-Python/tests/- Complete test frameworkdocs/Secure-Coding-Guide-for-Python/pyproject.toml- Project configurationdocs/Secure-Coding-Guide-for-Python/tox.ini- Multi-version testing configdocs/Secure-Coding-Guide-for-Python/.gitignore- Ignore test artifactsdocs/Secure-Coding-Guide-for-Python/generate_test_summary.sh- Summary scriptdocs/Secure-Coding-Guide-for-Python/KNOWN_ISSUES.md- Reference of existing issues
Modified Files:
docs/Secure-Coding-Guide-for-Python/CONTRIBUTING.md- Added testing instructions- Fixed typo: Renamed
compliants02.py→compliant02.py
Testing
All 765 tests collected, 531 passed, 80 failures (pre-existing issues), 154 skipped.
Tests run successfully across Python 3.9-3.14 in CI/CD.
- Ngôn ngữ chính
- Python
- Star
- 2
- Fork
- 2
- Merge trung bình
- 11 phút
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ossf/python-secure-coding-guide
-
pyscg-0051 should use a context managerCó thể đã có người làm @s19110 đã nhận 8 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
ossf/python-secure-coding-guide#1 · 4 bình luận · 1 người được giao ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 65/100
ossf/python-secure-coding-guide#29 · 1 bình luận ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
Tất cả issue của ossf/python-secure-coding-guide
Issue tương tự
-
README Quick Start query command fails, and doctor points to a missing Prerequisites sectionĐang mởdocumentation type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
add entry to blockĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
StevenBlack/hosts#3299 ·
-
`garak --report` overwrites the input report when its name has no ".report"Có thể đã có người làm @0z5a đã nhận hôm nay. Đang mởneeds-triage
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 2 ngày
-
trace: Pi's 1-hour cache writes are priced at 1.25x, but billed at 2xCó thể đã có người làm @Shizoqua đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
microsoft/TokenEconomizer#221 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
plot_graph crashes when a mesh node has no m2m edgeCó thể đã có người làm @tygvi đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
mllam/neural-lam#883 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày