Skip to main content

Pytest plugin for generating test cases with YAML. In test cases, you can use markers, fixtures, variables, and even call Python functions.

Project description

pytest-yaml-sanmu

pytest-yaml-sanmu is a plugin for pytest_ that considers YAML files as test case.

In this way, we can use markers, fixtures, variables, and even call Python functions in YAML.

For more information, please click here .

Require

python>=3.12
pytest>=8.2
pyyaml~=6.0
pyyaml-include~=1.3.1

Install

pip install pytest-yaml-sanmu

Config

# pytest.ini

[pytest]
# To execute YAML files starting with "test_"
yaml_run_case = true

Usage

1. Write tests

# test_api.yaml

name: fetch baidu # Each test case has a name
steps:                 # Each test case has multiple steps

  - request:           # steps 1: send request
      method: get
      url: https://www.baidu.com

  - response:          # steps 2: assert response
      status_code: 200
      text: "*baidu*"

2. Write Hook

# conftest.py

import requests
import responses_validator


def pytest_yaml_run_step(item):
    step = item.current_step
    request = step.get('request')
    response = step.get('response')

    if request:
        print(f'url={request["url"]}')
        item.resp = requests.request(**request)

    if response:
        responses_validator.validator(item.resp, **response)

    return True

3. Run pytest

(.venv) ~/pytest-yaml-demo>pytest
================== test session starts ==================
platform win32 -- Python 3.12.2, pytest-8.2.2, pluggy-1.5.0
rootdir: ~/pytest-yaml-demo
configfile: pytest.ini
plugins: allure-pytest-2.13.5, yaml-0.3.0.dev3
collected 1 item                                                                                 

test_api.yaml .                            [100%]

================== 1 passed in 0.22s ================== 

FeedBack

WeChat: python_sanmu

Article

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

pytest_yaml_sanmu-1.1.1-cp313-cp313-win_amd64.whl (244.2 kB view details)

Uploaded CPython 3.13Windows x86-64

pytest_yaml_sanmu-1.1.1-cp313-cp313-musllinux_1_2_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

pytest_yaml_sanmu-1.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pytest_yaml_sanmu-1.1.1-cp313-cp313-macosx_11_0_arm64.whl (254.0 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pytest_yaml_sanmu-1.1.1-cp313-cp313-macosx_10_13_x86_64.whl (262.8 kB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

pytest_yaml_sanmu-1.1.1-cp312-cp312-win_amd64.whl (248.2 kB view details)

Uploaded CPython 3.12Windows x86-64

pytest_yaml_sanmu-1.1.1-cp312-cp312-musllinux_1_2_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

pytest_yaml_sanmu-1.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pytest_yaml_sanmu-1.1.1-cp312-cp312-macosx_14_0_arm64.whl (259.9 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

pytest_yaml_sanmu-1.1.1-cp312-cp312-macosx_13_0_x86_64.whl (268.9 kB view details)

Uploaded CPython 3.12macOS 13.0+ x86-64

pytest_yaml_sanmu-1.1.1-cp312-cp312-macosx_11_0_arm64.whl (259.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pytest_yaml_sanmu-1.1.1-cp312-cp312-macosx_10_13_x86_64.whl (269.0 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

File details

Details for the file pytest_yaml_sanmu-1.1.1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for pytest_yaml_sanmu-1.1.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 47b0288542e5cf79c22afd110d0587076488f9038e72e1c28030630b23fcbfed
MD5 58f8c1fff2d58270296573ff78a4e049
BLAKE2b-256 b4a8316799ca8221d414d3dcd0858184d7b5ed0af09121fe23284b4422560208

See more details on using hashes here.

File details

Details for the file pytest_yaml_sanmu-1.1.1-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pytest_yaml_sanmu-1.1.1-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ff499eb044760fabddd15fb425bd46a8c3564de3771eaa712d8ec0404df6c06c
MD5 1221941fa97cf9818f2efd32a5ed2918
BLAKE2b-256 a85aaf1ae597a27bb1d7cb451b13ee2b15d81728f3c533adb7bd62ada9d73869

See more details on using hashes here.

File details

Details for the file pytest_yaml_sanmu-1.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pytest_yaml_sanmu-1.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a10d40a13ff73a3fea5182490bfa122ae8c594a1a6fa9930952a315842b5f47a
MD5 bb67a2398124c031a61b8acdaa0e1cfc
BLAKE2b-256 4cdb6b00445cf5380a28a2bf7532a44c38a55a8534eeee5c8c7d45d9a411af1c

See more details on using hashes here.

File details

Details for the file pytest_yaml_sanmu-1.1.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pytest_yaml_sanmu-1.1.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0ea5adb44af654f61fbf998d62db280a65fd2fd9817444f8dc2ca1b7f4576714
MD5 a6463a63707a4532e29397eb5cb52aa5
BLAKE2b-256 475df986ad806f194460d01487964fcae5bf34c87643c10679b7154b09c9270b

See more details on using hashes here.

File details

Details for the file pytest_yaml_sanmu-1.1.1-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for pytest_yaml_sanmu-1.1.1-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 89edf582416a69637fdbcc447cd8d32295ddc4abbde55041334ee9620c6c3297
MD5 789bffcc86935920e2b2332b86d6519d
BLAKE2b-256 5a3e1039caf1c2d576747983dc217d035faaa9cde92910054cdb4504257fce46

See more details on using hashes here.

File details

Details for the file pytest_yaml_sanmu-1.1.1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for pytest_yaml_sanmu-1.1.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 adf81487010bc32bf9a3b54580715d79bc8abff0e53567dfc500723526937157
MD5 3f97ea8313da4107de826a9b30c349d8
BLAKE2b-256 a479b50a4cc921b8fca001daaf1f3b67845fb1025ad1efb427ada2a680192194

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_yaml_sanmu-1.1.1-cp312-cp312-win_amd64.whl:

Publisher: publish-to-pypi.yml on dongfangtianyu/pytest-yaml-sanmu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_yaml_sanmu-1.1.1-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pytest_yaml_sanmu-1.1.1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 88bd784e21dfcd744970c068e6e7502a1584a662a6b62f907988f7c3d0ee3a7a
MD5 796c3f793a139ace2728792b4c1c558f
BLAKE2b-256 6e64dc714e791f5f4ef73f465a5fffffd45ccedca484f09d4451828edc3e138e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_yaml_sanmu-1.1.1-cp312-cp312-musllinux_1_2_x86_64.whl:

Publisher: publish-to-pypi.yml on dongfangtianyu/pytest-yaml-sanmu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_yaml_sanmu-1.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pytest_yaml_sanmu-1.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 65de0e3bd77cd50acedcf93917d6c731360ba473e08114d3dbf3dbf3751f1b85
MD5 7a0b3a73e25d70615796125b3e2f85b2
BLAKE2b-256 fdc4b06e89ceb76bd62be956b6233253b4c0871de2f00d3a0f0fcc15da2d68e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_yaml_sanmu-1.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-to-pypi.yml on dongfangtianyu/pytest-yaml-sanmu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_yaml_sanmu-1.1.1-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for pytest_yaml_sanmu-1.1.1-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 3d17f59e2f6cb42e9fd49778460633df5f852dcb947b23dda3c8fbc6b72da978
MD5 1803399fb13792069b3e4ae075704b01
BLAKE2b-256 09783fc425fbd4e343b09a98235fc12a15c9ce1aa6202711f8a8e7b71d8df051

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_yaml_sanmu-1.1.1-cp312-cp312-macosx_14_0_arm64.whl:

Publisher: publish-to-pypi.yml on dongfangtianyu/pytest-yaml-sanmu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_yaml_sanmu-1.1.1-cp312-cp312-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for pytest_yaml_sanmu-1.1.1-cp312-cp312-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 86c6f4bc3a9e0b6d834df40c20bf67ef59ccdb2de2bd17f3b87c48b1618e5d9f
MD5 35c70b38b518d1fb63103edca760dd59
BLAKE2b-256 55ea77d1efa9650e9d5d58ce4b6b1113adcc816ef7ccb9594eeaed78ef135c5b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_yaml_sanmu-1.1.1-cp312-cp312-macosx_13_0_x86_64.whl:

Publisher: publish-to-pypi.yml on dongfangtianyu/pytest-yaml-sanmu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_yaml_sanmu-1.1.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pytest_yaml_sanmu-1.1.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 49b598b951f839cec21954395081d795034bf8f479fb7bba729d6fba2f73ccfe
MD5 de3447c4a2c9f764bbafbad2a0ec01a6
BLAKE2b-256 923f9311868ba4a42f97cf762888c3c12cd25cea39531558c19b46bcdc8a59f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_yaml_sanmu-1.1.1-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: publish-to-pypi.yml on dongfangtianyu/pytest-yaml-sanmu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_yaml_sanmu-1.1.1-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for pytest_yaml_sanmu-1.1.1-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 8d419ba6435b1a17e57859a61763b3a47b94c98951bf2b3afe6f8e4b824e361d
MD5 ed810bc64bcaf3c1bfbf9ccb42d6d061
BLAKE2b-256 4040edd9506d4feca83faca06c2b15d01a127e1b6489e9b49f9943d6026aca25

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_yaml_sanmu-1.1.1-cp312-cp312-macosx_10_13_x86_64.whl:

Publisher: publish-to-pypi.yml on dongfangtianyu/pytest-yaml-sanmu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page