pySCG: Add a testing framework for Python code examples and documentation
まだ誰も着手していません。
- #1011 @tommcd による — マージされずにクローズ
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 20/100
- issue の種類
- 機能追加
- 明瞭さ
- 明確に書かれている
- 活発さ
- 停滞
- 技術スタック
- github-actions, python
- 領域
- ci-cd, documentation, testing
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Python
- スター
- 2
- フォーク
- 2
- 平均マージ
- 11分
- マージ済み PR(30日)
- 2
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ossf/python-secure-coding-guide のほかの issue
-
pyscg-0051 should use a context manager対応中かも @s19110 が 8 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
ossf/python-secure-coding-guide#1 · コメント 4 件 · 担当者 1 名 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
ossf/python-secure-coding-guide#29 · コメント 1 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
ossf/python-secure-coding-guide の issue をすべて見る
似ている issue
-
documentation type/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
add entry to blockオープン
難易度 1/5 1時間未満 初心者へのやさしさ 65/100
StevenBlack/hosts#3299 ·
-
`garak --report` overwrites the input report when its name has no ".report"対応中かも @0z5a が今日担当しました。 オープンneeds-triage
難易度 2/5 半日 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信
-
trace: Pi's 1-hour cache writes are priced at 1.25x, but billed at 2x対応中かも @Shizoqua が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
microsoft/TokenEconomizer#221 ·
メンテナーはふだん 1 日以内に返信
-
plot_graph crashes when a mesh node has no m2m edge対応中かも @tygvi が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
mllam/neural-lam#883 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信