2.7 KiB
2.7 KiB
Preferred Test Strategy
Use one of the following patterns depending on page type:
-
Dynamic code-block extraction (preferred for offline docs)
- Extract Python/Bash code blocks from markdown AST analyzer, then execute them directly in tests.
- Benefit: test logic stays automatically aligned with docs.
- Basic idea: Use
ReadmeSnippet.extract_readme_snippetsto extract a list of code blocks as a global variable in file, use this list aspytest.mark.parametrizeparameters, and pass each snippet item toexample_runner.runinside the parametrized test. Additionally pass anoutput_subfolderargument for the 2nd-level output folder explained in Output Directory Structure below. If any extra environment variable is need for a test (e.g., the example script reads it),example_runner.runalso accepts a 3rdenvparameter. - See tests/examples/offline_inference/test_text_to_image.py for reference implementation.
-
Explicit copied scripts (used by online docs for now until further update)
- For online serving pages, it is acceptable to copy code from docs into dedicated test functions, because only client-side, request-sending scripts are tested.
- Benefit: dynamic extraction is overly complex: need to tell server-launch and client-request scripts.
- Requirement: copied test code must be kept in sync with doc updates.
Test Case Naming Convention
- Dynamic code extraction (auto-generated internally):
test_{single_function_name_matching_file_name}[h2_heading_00X]- Example:
test_text_to_image[basic_usage_001]
- Explicit copied scripts:
test_{h2_heading_00X}[{dummy_param_id_for_omni_server}]- Example:
test_api_calls_001[omni_server0]
Runtime Configuration
In the example code tests, do not reduce num_inference_steps just to speed up the tests unless there is a strong CI reliability reason to do otherwise.
Skipping Rules
You may skip examples falling in the following categories using pytest.mark.skip or pytest.skip:
- Gradio UI scripts
- Scenarios that significantly overlap with existing tests and add little new coverage.
Output Directory Structure
Use a three-layer output structure to store output artifacts:
- Root output directory
- Auto-detected from
OUTPUT_DIRenv var or auto-generated under/tmp.
- Auto-detected from
- Doc-page directory
- Define and use a clear page-level folder name in each
test_*.pyyourself (abbreviations are acceptable, e.g.,example_offline_t2i).
- Define and use a clear page-level folder name in each
- Test-case directory
- Must match the case identifier (e.g.,
basic_usage_001). - Auto-generated for dynamic extracted tests.
- Must match the case identifier (e.g.,