{"id":20646267,"url":"https://github.com/boon-code/pytest-advanced-use-cases","last_synced_at":"2026-04-17T20:31:10.429Z","repository":{"id":137248080,"uuid":"220628849","full_name":"boon-code/pytest-advanced-use-cases","owner":"boon-code","description":"Collection of ideas for advanced pytest use cases","archived":false,"fork":false,"pushed_at":"2019-11-10T18:21:39.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-09T16:36:19.263Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/boon-code.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-09T10:55:20.000Z","updated_at":"2019-11-10T18:21:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"8e3b7638-63ee-49f6-b82c-ace474f2aadc","html_url":"https://github.com/boon-code/pytest-advanced-use-cases","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/boon-code/pytest-advanced-use-cases","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boon-code%2Fpytest-advanced-use-cases","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boon-code%2Fpytest-advanced-use-cases/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boon-code%2Fpytest-advanced-use-cases/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boon-code%2Fpytest-advanced-use-cases/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/boon-code","download_url":"https://codeload.github.com/boon-code/pytest-advanced-use-cases/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boon-code%2Fpytest-advanced-use-cases/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31944921,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T17:29:20.459Z","status":"ssl_error","status_checked_at":"2026-04-17T17:28:47.801Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T16:25:01.958Z","updated_at":"2026-04-17T20:31:10.412Z","avatar_url":"https://github.com/boon-code.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Pytest Advanced use cases\n=========================\n\nA collection of ideas how to use *Pytest* in more advanced scenarios\n\n\n# Manual DuT setup\n\nVery simple idea declaring multiple fixtures to represent the state\n\n## Setup\n\n1. Declare multiple fixtures for different operating states (`manual_duts.py`)\n2. Derive different fixtures that are used in the test cases\n\n    - `dut_default` to represent the _normal_ operation condition\n    - `dut_debug`   on special operating mode for extended testability\n    - `dut_off`     DuT is powered down before starting the test case\n\n3. Manual tests can be found in `test_dut_state_manual.py`\n\n\n## Conclusion\n\nWorks fine, but quite cumbersome to in the test cases and in the fixtures:\n- Duplication\n- Different names for the DuT's\n- Less protection against mistakes like messing up the state in a test case that uses `dut`\n  or `session_dut`\n\n\n# DuT setup using markers\n\nUse only one fixture for the DuT and define the requested state via a marker\n\n## Setup\n\n1. Declare a marker `dut_state(state_name)` (in `conftest.py`) and one fixture for the DuT\n   `auto_dut` (based on `session_auto_dut`) in `auto_dut.py`\n2. Check markers of the *function*-scoped `auto_dut` fixture.\n\n    - if not set, reset to off state\n    - if `dut_state` marker was found, ensure the DuT is in that state\n    \n3. Automatic tests can be found in `test_auto_dut_state.py`\n\n\n## Conclusion\n\nIt seems like the better approach:\n- Only one fixture and less code duplication\n- Automatically handle the case when no state is specified\n- Mixing function and module scoped tests works as expected:\n\n    - If marker is set on module scope, it's not allowed to defined another marker. An error\n      will be raised and inform about the problem (see `auto_dut` fixture)\n    - Class level markers can also be used to structure test runs and avoid having to repeat\n      the declaration of `dut_state` over and over\n\n- Also `pytest.mark.parametrize()` works like a charm, see `test_auto_dut_parametrized.py`\n\n\n# Pytest and Behavior-driven development (BDD)\n\n## TODO\n\n- Try `pytest-bdd`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboon-code%2Fpytest-advanced-use-cases","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fboon-code%2Fpytest-advanced-use-cases","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboon-code%2Fpytest-advanced-use-cases/lists"}