0
0
PyTesttesting~8 mins

Single parameter in PyTest - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Single parameter
Folder Structure
tests/
├── test_example.py
├── conftest.py
utilities/
├── helpers.py
pytest.ini
Test Framework Layers
  • Tests: Contains test files like test_example.py where test functions with single parameters are defined.
  • Fixtures (conftest.py): Provides reusable setup code and test data injection.
  • Utilities: Helper functions or modules to support tests.
  • Configuration: pytest.ini for pytest settings and options.
Configuration Patterns

Use pytest.ini to define default options like test paths and markers.

Manage environments and credentials via environment variables or fixtures in conftest.py.

Example: Use a fixture to provide a single parameter value to tests.

Test Reporting and CI/CD Integration
  • Use pytest built-in reporting with clear pass/fail output.
  • Integrate with CI/CD tools (GitHub Actions, Jenkins) to run tests automatically on code changes.
  • Generate reports with plugins like pytest-html for readable test summaries.
Framework Design Principles
  1. Keep tests simple: Use single parameters to test one condition at a time.
  2. Use fixtures: Provide test data cleanly and reuse setup code.
  3. Organize tests logically: Group related tests in files and folders.
  4. Clear naming: Name test functions to describe what single parameter they test.
  5. Isolate tests: Each test should be independent to avoid side effects.
Self Check

Where would you add a new fixture that provides a single parameter value for multiple tests?

Key Result
Organize pytest tests with single parameters using fixtures and clear folder structure.