testinfra-bdd


Nametestinfra-bdd JSON
Version 3.1.1 PyPI version JSON
download
home_pagehttps://github.com/cbdq-io/testinfra-bdd
SummaryAn interface between pytest-bdd and pytest-testinfra.
upload_time2024-12-18 08:57:16
maintainerNone
docs_urlNone
authorCloud Based DQ Ltd.
requires_python>=3.9
licenseNone
keywords testinfra bdd
VCS
bugtrack_url
requirements bandit build colorama coverage exceptiongroup flake8 flake8-docstrings flake8-quotes gitchangelog gitdb GitPython iniconfig isort jmespath Mako mando markdown-it-py MarkupSafe mccabe mdurl packaging parse parse_type pathspec pbr pluggy pycodestyle pydocstyle pyflakes Pygments pyproject_hooks pystache pytest pytest-bdd pytest-cov pytest-testinfra PyYAML radon rich setuptools six smmap snowballstemmer stevedore tomli typing_extensions urllib3 wheel yamllint
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # testinfra-bdd

[![CI](https://github.com/cbdq-io/testinfra-bdd/actions/workflows/ci.yml/badge.svg)](https://github.com/cbdq-io/testinfra-bdd/actions/workflows/ci.yml)
[![Maintainability](https://api.codeclimate.com/v1/badges/5482c55d78b369a0a55e/maintainability)](https://codeclimate.com/github/cbdq-io/testinfra-bdd/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/5482c55d78b369a0a55e/test_coverage)](https://codeclimate.com/github/cbdq-io/testinfra-bdd/test_coverage)
[![testinfra-bdd](https://snyk.io/advisor/python/testinfra-bdd/badge.svg)](https://snyk.io/advisor/python/testinfra-bdd)

An interface between
[pytest-bdd](https://pytest-bdd.readthedocs.io/en/latest/)
and
[pytest-testinfra](https://testinfra.readthedocs.io/en/latest/index.html).

## Defining Scenarios

Given a directory structure of:

```shell
"."

└── "tests"
    ├── "features"
    │   ├── "example.feature"
    └── "step_defs"
        └── "test_example.py"
```

The file `tests/features/example.feature` could look something like:

```gherkin
Feature: Example of Testinfra BDD
  Give an example of all the possible Given, When and Then steps.

  The Given steps to skip the address and port tests when running under
  GitHub actions are not part of the testinfra-bdd package itself, but are
  required as GitHub/Azure does not allow Ping/ICMP traffic.

  Scenario: Skip Tests if Host is Windoze
    Given the TestInfra host with URL "docker://sut" is ready within 10 seconds
    # The system property can be one of:
    #   - type (e.g. linux).
    #   - distribution (e.g. debian).
    #   - release (e.g. 11).
    #   - codename (e.g. bullseye).
    #   - arch (e.g. x86_64).
    #   - hostname (e.g. sut).
    #   - connection_type (e.g. docker or ssh).
    When the TestInfra system property type is not Windoze skip tests

  Scenario Outline: Test for Absent Resources
    Given the TestInfra host with URL "docker://sut" is ready within 10 seconds
    When the TestInfra <resource_type> is "foo"
    Then the TestInfra <resource_type> is absent
    Examples:
      | resource_type |
      | user          |
      | group         |
      | package       |
      | file          |
      | pip package   |

  Scenario Outline: Test for Absent Non-Quoted Resources
    # Same as the example above except the resources are not quoted.
    Given the TestInfra host with URL "docker://sut" is ready within 10 seconds
    When the TestInfra <resource_type> is foo
    Then the TestInfra <resource_type> state is absent
    Examples:
      | resource_type |
      | user          |
      | group         |
      | package       |
      | file          |
      | pip package   |

  Scenario: User Checks
    Given the TestInfra host with URL "docker://sut" is ready
    When the TestInfra user is "ntp"
    Then the TestInfra user is present
    # Alternative method of checking the state of a resource.
    And the TestInfra user state is present
    And the TestInfra user group is ntp
    And the TestInfra user uid is 101
    And the TestInfra user gid is 101
    And the TestInfra user home is /nonexistent
    And the TestInfra user shell is /usr/sbin/nologin

  Scenario: File Checks
    Given the TestInfra host with URL "docker://sut" is ready
    When the TestInfra file is /etc/ntp.conf
    # Expected state can be present or absent.
    Then the TestInfra file is present
    # Alternative method of checking the state of a resource.
    And the TestInfra file state is present
    # Valid types to check for are file, directory, pipe, socket or symlink.
    And the TestInfra file type is file
    And the TestInfra file owner is ntp
    And the TestInfra file group is ntp
    And the TestInfra file contents contains "debian.pool.ntp"
    And the TestInfra file contents contains the regex ".*pool [0-9].debian.pool.ntp.org iburst"
    # The expected mode must be specified as an octal.
    And the TestInfra file mode is 0o544

  Scenario: File Executable Checks
    Given the TestInfra host with URL "docker://sut" is ready
    When the TestInfra file is /bin/ls
    Then the TestInfra file is present
    And the TestInfra file is executable

  Scenario: Group Checks
    Given the TestInfra host with URL "docker://sut" is ready
    When the TestInfra group is "ntp"
    # Can check if the group is present or absent.
    Then the TestInfra group is present
    # Alternative method of checking the state of a resource.
    And the TestInfra group state is present
    And the TestInfra group gid is 101

  Scenario: Group Membership
    Given the TestInfra host with URL "docker://sut" is ready
    When the TestInfra group is "sudo"
    And the TestInfra user is "bar"
    Then the TestInfra group contains the user "bar"
    And the TestInfra user groups include "sudo"

  Scenario: Running Commands
    Given the TestInfra host with URL "docker://sut" is ready
    When the TestInfra command is "ntpq -np"
    Then the TestInfra command return code is 0
    And the TestInfra command "ntpq" exists in path
    And the TestInfra command stdout contains "remote"
    And the TestInfra command stdout does not contain "foo"

  Scenario: System Package
    Given the TestInfra host with URL "docker://sut" is ready
    When the TestInfra package is ntp
    # Can check if the package is absent, present or installed.
    Then the TestInfra package is installed
    And the TestInfra package version will be greater than or equal to 1:4.2.8p15+dfsg-1

  Scenario: Python Package
    Given the TestInfra host with URL "docker://sut" is ready
    When the TestInfra pip package is testinfra-bdd
    # Can check if the package is absent or present.
    Then the TestInfra pip package is present
    And the TestInfra pip package version is 3.1.1
    And the TestInfra pip package version will be greater than or equal to 3.0.5
    # Check that installed packages have compatible dependencies.
    And the TestInfra pip check is OK

  Scenario Outline: Service Checks
    Given the TestInfra host with URL "docker://sut" is ready
    When the TestInfra service is <service>
    Then the TestInfra service is <running_state>
    And the TestInfra service is <enabled_state>
    Examples:
      | service | running_state | enabled_state |
      | ntp     | running       | enabled       |
      | named   | not running   | not enabled   |

  Scenario: Test Running Processes
    Given the TestInfra host with URL "docker://sut" is ready
    # Processes are selected using filter() attributes names are
    # described in the ps man page.
    When the TestInfra process filter is "user=root,comm=ntpd"
    Then the TestInfra process count is 1

  Scenario Outline: Test Pip Packages are Latest Versions
    Given the TestInfra host with URL "docker://sut" is ready
    When the TestInfra pip package is <pip_package>
    Then the TestInfra pip package is present
    And the TestInfra pip package is <status>
    Examples:
      | pip_package      | status |
      | pytest-bdd       | latest |
      | pytest-testinfra | latest |
      | testinfra-bdd    | latest |

  Scenario Outline:  Check Sockets
    # This checks that NTP is listening but SSH isn't.
    # The socket url is defined at https://testinfra.readthedocs.io/en/latest/modules.html#socket
    Given the TestInfra host with URL "docker://sut" is ready within 10 seconds
    When the TestInfra socket is <url>
    Then the TestInfra socket is <expected_state>
    Examples:
      | url       | expected_state |
      | udp://123 | listening      |
      | tcp://22  | not listening  |

  Scenario: Skip Tests Due to Environment Variable
    Given the TestInfra host with URL "docker://java11" is ready
    When the TestInfra environment variable PYTHONPATH is .:.. skip tests

  Scenario: Check Network Address
    Given the TestInfra host with URL "docker://sut" is ready within 10 seconds
    When the TestInfra environment variable GITHUB_ACTIONS is true skip tests
    And the TestInfra address is www.google.com
    Then the TestInfra address is resolvable
    And the TestInfra address is reachable

  Scenario: Check Network Address With Port
    Given the TestInfra host with URL "docker://sut" is ready within 10 seconds
    When the TestInfra environment variable GITHUB_ACTIONS is true skip tests
    And the TestInfra address and port is www.google.com:443
    Then the TestInfra address is resolvable
    And the TestInfra address is reachable
    And the TestInfra port is reachable

  Scenario: Check Java is Installed in the Path
    Given the TestInfra host with URL "docker://java11" is ready within 10 seconds
    Then the TestInfra command "java" exists in path

  Scenario: Check Java 11 is Installed
    Given the TestInfra host with URL "docker://java11" is ready
    When the TestInfra command is "java -version"
    And the TestInfra package is java-11-amazon-corretto-devel
    Then the TestInfra command stderr contains "Corretto-11"
    And the TestInfra command stderr contains the regex "openjdk version \"11\\W[0-9]"
    And the TestInfra command stdout is empty
    And the TestInfra command return code is 0
    And the TestInfra package is installed

  Scenario: Check for an Expected Value
   # In this example we set the expected_value to "foo"
   Given the TestInfra host with URL "docker://sut" is ready
   And the TestInfra expected value is "foo"
   When the TestInfra command is "echo foo"
   Then the TestInfra command stdout contains the expected value

  Scenario Outline: Check Contents of JSON File With JMESPath
    Given the TestInfra host with URL "docker://sut" is ready
    When the TestInfra file is /tmp/john-smith.json
    Then the TestInfra JMESPath expression <expression> returns <expected_value>
    Examples:
      | expression    | expected_value |
      | firstName     | John           |
      | lastName      | Smith          |
      | age           | 27             |
      | address.state | NY             |
      | spouse        | None           |
```

and `tests/step_defs/test_example.py` contains the following:

```python
"""Examples of step definitions for Testinfra BDD feature tests."""
import testinfra_bdd
from pytest_bdd import given, scenarios

scenarios('../features/example.feature')


# Ensure that the PyTest fixtures provided in testinfra-bdd are available to
# your test suite.
pytest_plugins = testinfra_bdd.PYTEST_MODULES


@given('the TestInfra expected value is "foo"', target_fixture='expected_value')
def the_expected_value_is_foo():
    """
    The expected value is "foo".

    The name and code is up to the user to develop.  However, the target
    fixture must be called 'expected_value'.
    """
    return 'foo'
```

## "Given" Steps

Given steps require that the URL of the system to be tested (SUT) is provided.
This URL should comply to the connection string for the [Testinfra connection
string](https://testinfra.readthedocs.io/en/latest/backends.html) (e.g.
docker://my-host).  Please note that the URL _must_ be enclosed in double
quotes.

Examples:

To connect to a Docker container called sut (fail if the target host is
not ready):

```gherkin
Given the TestInfra host with URL "docker://java11" is ready
```

To connect to a Docker container called sut but give it 60 seconds to become
ready, use the following:

```gherkin
Given the TestInfra host with URL "docker://sut" is ready within 60 seconds
```

If the host does not become available after 60 seconds, fail the tests.

### Writing a customized "Given" Step

It may be that you may want to create a customized "Given" step.  An example
could be that the hosts to be tested may be parametrized.  The "Given" step
must return a target fixture called "testinfra_bdd_host" so that the rest of
the Testinfra BDD fixtures will function.  This fixture is a instance of the
`testinfra_bdd.`

The "Given" step should also ascertain that the target host is ready (one
can use the `is_host_ready` function for that).

An example is:

```python
from pytest_bdd import given
from testinfra_bdd import TestinfraBDD

@given('my host is ready', target_fixture='testinfra_bdd_host')
def my_host_is_ready():
    """
    Specify that the target host is a docker container called
    "my-host" and wait up to 60 seconds for the host to be ready.
    """
    host = TestinfraBDD('docker://my-host')
    assert host.is_host_ready(60), 'My host is not ready.'
    return host

...
```

## "When" Steps

When steps require that a "Given" step has been executed beforehand.  They
allow the user to either skip tests if the host does not match an expected
profile.  They also allow the user to specify which resource or is to be
tested.

### Skip Tests if Host Profile Does Not Match

It may be useful to skip tests if you find that the system under test doesn't
match an expected profile (e.g. the system is not debian as expected).  This
can be achieved by comparing against the following configurations:

- The OS Type (e.g. linux).
- The distribution name (e.g. debian).
- The OS release (e.g. 11).
- The OS codename if relevant (e.g. bullseye).
- The host architecture (e.g. x86_64).
- The hostname (e.g. sut)

Example:

```gherkin
  Scenario: Skip Tests if Host is Windoze
    Given the TestInfra host with URL "docker://sut" is ready within 10 seconds
    When the TestInfra system property type is not Windoze skip tests
```

## Upgrading from 2.Y.Z to 3.0.0

We introduced a number of breaking changes, namely:
- A change to the Domain Specific Language (DSL).
- Moving to TestInfra 9 and dropping support for 6, 7 and 8.
- Dropping support for EOL versions of Python (3.6, 3.7 and 3.8).

The changes for the DSL are pretty basic.  We identified a need to namespace
the TestInfra tests to stop clashes with other BDD feature code.  If your
old code looked something like:

```gherkin
  Scenario: System Package
    Given the host with URL "docker://sut" is ready
    When the package is ntp
    Then the package is installed
```

Then change the code to:

```gherkin
  Scenario: System Package
    Given the TestInfra host with URL "docker://sut" is ready
    When the TestInfra package is ntp
    Then the TestInfra package is installed
```

All example code above has been updated to the new format for guidance.

## Upgrading from 1.Y.Z to 2.0.0

We split the single package into multiple source files.  This means a minor
but nonetheless breaking change in your step definitions (all feature files
can remain as they are).  The change is how one sets `pytest_plugins`.

### Old Code

```python
pytest_plugins = ['testinfra_bdd']
```

### New Code

```python
pytest_plugins = testinfra_bdd.PYTEST_MODULES
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/cbdq-io/testinfra-bdd",
    "name": "testinfra-bdd",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "testinfra, bdd",
    "author": "Cloud Based DQ Ltd.",
    "author_email": "info@cbdq.io",
    "download_url": "https://files.pythonhosted.org/packages/a6/91/485415da368b47b3c68892021e26e5f707526290f3b9a45cf926278b027f/testinfra_bdd-3.1.1.tar.gz",
    "platform": null,
    "description": "# testinfra-bdd\n\n[![CI](https://github.com/cbdq-io/testinfra-bdd/actions/workflows/ci.yml/badge.svg)](https://github.com/cbdq-io/testinfra-bdd/actions/workflows/ci.yml)\n[![Maintainability](https://api.codeclimate.com/v1/badges/5482c55d78b369a0a55e/maintainability)](https://codeclimate.com/github/cbdq-io/testinfra-bdd/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/5482c55d78b369a0a55e/test_coverage)](https://codeclimate.com/github/cbdq-io/testinfra-bdd/test_coverage)\n[![testinfra-bdd](https://snyk.io/advisor/python/testinfra-bdd/badge.svg)](https://snyk.io/advisor/python/testinfra-bdd)\n\nAn interface between\n[pytest-bdd](https://pytest-bdd.readthedocs.io/en/latest/)\nand\n[pytest-testinfra](https://testinfra.readthedocs.io/en/latest/index.html).\n\n## Defining Scenarios\n\nGiven a directory structure of:\n\n```shell\n\".\"\n\n\u2514\u2500\u2500 \"tests\"\n    \u251c\u2500\u2500 \"features\"\n    \u2502   \u251c\u2500\u2500 \"example.feature\"\n    \u2514\u2500\u2500 \"step_defs\"\n        \u2514\u2500\u2500 \"test_example.py\"\n```\n\nThe file `tests/features/example.feature` could look something like:\n\n```gherkin\nFeature: Example of Testinfra BDD\n  Give an example of all the possible Given, When and Then steps.\n\n  The Given steps to skip the address and port tests when running under\n  GitHub actions are not part of the testinfra-bdd package itself, but are\n  required as GitHub/Azure does not allow Ping/ICMP traffic.\n\n  Scenario: Skip Tests if Host is Windoze\n    Given the TestInfra host with URL \"docker://sut\" is ready within 10 seconds\n    # The system property can be one of:\n    #   - type (e.g. linux).\n    #   - distribution (e.g. debian).\n    #   - release (e.g. 11).\n    #   - codename (e.g. bullseye).\n    #   - arch (e.g. x86_64).\n    #   - hostname (e.g. sut).\n    #   - connection_type (e.g. docker or ssh).\n    When the TestInfra system property type is not Windoze skip tests\n\n  Scenario Outline: Test for Absent Resources\n    Given the TestInfra host with URL \"docker://sut\" is ready within 10 seconds\n    When the TestInfra <resource_type> is \"foo\"\n    Then the TestInfra <resource_type> is absent\n    Examples:\n      | resource_type |\n      | user          |\n      | group         |\n      | package       |\n      | file          |\n      | pip package   |\n\n  Scenario Outline: Test for Absent Non-Quoted Resources\n    # Same as the example above except the resources are not quoted.\n    Given the TestInfra host with URL \"docker://sut\" is ready within 10 seconds\n    When the TestInfra <resource_type> is foo\n    Then the TestInfra <resource_type> state is absent\n    Examples:\n      | resource_type |\n      | user          |\n      | group         |\n      | package       |\n      | file          |\n      | pip package   |\n\n  Scenario: User Checks\n    Given the TestInfra host with URL \"docker://sut\" is ready\n    When the TestInfra user is \"ntp\"\n    Then the TestInfra user is present\n    # Alternative method of checking the state of a resource.\n    And the TestInfra user state is present\n    And the TestInfra user group is ntp\n    And the TestInfra user uid is 101\n    And the TestInfra user gid is 101\n    And the TestInfra user home is /nonexistent\n    And the TestInfra user shell is /usr/sbin/nologin\n\n  Scenario: File Checks\n    Given the TestInfra host with URL \"docker://sut\" is ready\n    When the TestInfra file is /etc/ntp.conf\n    # Expected state can be present or absent.\n    Then the TestInfra file is present\n    # Alternative method of checking the state of a resource.\n    And the TestInfra file state is present\n    # Valid types to check for are file, directory, pipe, socket or symlink.\n    And the TestInfra file type is file\n    And the TestInfra file owner is ntp\n    And the TestInfra file group is ntp\n    And the TestInfra file contents contains \"debian.pool.ntp\"\n    And the TestInfra file contents contains the regex \".*pool [0-9].debian.pool.ntp.org iburst\"\n    # The expected mode must be specified as an octal.\n    And the TestInfra file mode is 0o544\n\n  Scenario: File Executable Checks\n    Given the TestInfra host with URL \"docker://sut\" is ready\n    When the TestInfra file is /bin/ls\n    Then the TestInfra file is present\n    And the TestInfra file is executable\n\n  Scenario: Group Checks\n    Given the TestInfra host with URL \"docker://sut\" is ready\n    When the TestInfra group is \"ntp\"\n    # Can check if the group is present or absent.\n    Then the TestInfra group is present\n    # Alternative method of checking the state of a resource.\n    And the TestInfra group state is present\n    And the TestInfra group gid is 101\n\n  Scenario: Group Membership\n    Given the TestInfra host with URL \"docker://sut\" is ready\n    When the TestInfra group is \"sudo\"\n    And the TestInfra user is \"bar\"\n    Then the TestInfra group contains the user \"bar\"\n    And the TestInfra user groups include \"sudo\"\n\n  Scenario: Running Commands\n    Given the TestInfra host with URL \"docker://sut\" is ready\n    When the TestInfra command is \"ntpq -np\"\n    Then the TestInfra command return code is 0\n    And the TestInfra command \"ntpq\" exists in path\n    And the TestInfra command stdout contains \"remote\"\n    And the TestInfra command stdout does not contain \"foo\"\n\n  Scenario: System Package\n    Given the TestInfra host with URL \"docker://sut\" is ready\n    When the TestInfra package is ntp\n    # Can check if the package is absent, present or installed.\n    Then the TestInfra package is installed\n    And the TestInfra package version will be greater than or equal to 1:4.2.8p15+dfsg-1\n\n  Scenario: Python Package\n    Given the TestInfra host with URL \"docker://sut\" is ready\n    When the TestInfra pip package is testinfra-bdd\n    # Can check if the package is absent or present.\n    Then the TestInfra pip package is present\n    And the TestInfra pip package version is 3.1.1\n    And the TestInfra pip package version will be greater than or equal to 3.0.5\n    # Check that installed packages have compatible dependencies.\n    And the TestInfra pip check is OK\n\n  Scenario Outline: Service Checks\n    Given the TestInfra host with URL \"docker://sut\" is ready\n    When the TestInfra service is <service>\n    Then the TestInfra service is <running_state>\n    And the TestInfra service is <enabled_state>\n    Examples:\n      | service | running_state | enabled_state |\n      | ntp     | running       | enabled       |\n      | named   | not running   | not enabled   |\n\n  Scenario: Test Running Processes\n    Given the TestInfra host with URL \"docker://sut\" is ready\n    # Processes are selected using filter() attributes names are\n    # described in the ps man page.\n    When the TestInfra process filter is \"user=root,comm=ntpd\"\n    Then the TestInfra process count is 1\n\n  Scenario Outline: Test Pip Packages are Latest Versions\n    Given the TestInfra host with URL \"docker://sut\" is ready\n    When the TestInfra pip package is <pip_package>\n    Then the TestInfra pip package is present\n    And the TestInfra pip package is <status>\n    Examples:\n      | pip_package      | status |\n      | pytest-bdd       | latest |\n      | pytest-testinfra | latest |\n      | testinfra-bdd    | latest |\n\n  Scenario Outline:  Check Sockets\n    # This checks that NTP is listening but SSH isn't.\n    # The socket url is defined at https://testinfra.readthedocs.io/en/latest/modules.html#socket\n    Given the TestInfra host with URL \"docker://sut\" is ready within 10 seconds\n    When the TestInfra socket is <url>\n    Then the TestInfra socket is <expected_state>\n    Examples:\n      | url       | expected_state |\n      | udp://123 | listening      |\n      | tcp://22  | not listening  |\n\n  Scenario: Skip Tests Due to Environment Variable\n    Given the TestInfra host with URL \"docker://java11\" is ready\n    When the TestInfra environment variable PYTHONPATH is .:.. skip tests\n\n  Scenario: Check Network Address\n    Given the TestInfra host with URL \"docker://sut\" is ready within 10 seconds\n    When the TestInfra environment variable GITHUB_ACTIONS is true skip tests\n    And the TestInfra address is www.google.com\n    Then the TestInfra address is resolvable\n    And the TestInfra address is reachable\n\n  Scenario: Check Network Address With Port\n    Given the TestInfra host with URL \"docker://sut\" is ready within 10 seconds\n    When the TestInfra environment variable GITHUB_ACTIONS is true skip tests\n    And the TestInfra address and port is www.google.com:443\n    Then the TestInfra address is resolvable\n    And the TestInfra address is reachable\n    And the TestInfra port is reachable\n\n  Scenario: Check Java is Installed in the Path\n    Given the TestInfra host with URL \"docker://java11\" is ready within 10 seconds\n    Then the TestInfra command \"java\" exists in path\n\n  Scenario: Check Java 11 is Installed\n    Given the TestInfra host with URL \"docker://java11\" is ready\n    When the TestInfra command is \"java -version\"\n    And the TestInfra package is java-11-amazon-corretto-devel\n    Then the TestInfra command stderr contains \"Corretto-11\"\n    And the TestInfra command stderr contains the regex \"openjdk version \\\"11\\\\W[0-9]\"\n    And the TestInfra command stdout is empty\n    And the TestInfra command return code is 0\n    And the TestInfra package is installed\n\n  Scenario: Check for an Expected Value\n   # In this example we set the expected_value to \"foo\"\n   Given the TestInfra host with URL \"docker://sut\" is ready\n   And the TestInfra expected value is \"foo\"\n   When the TestInfra command is \"echo foo\"\n   Then the TestInfra command stdout contains the expected value\n\n  Scenario Outline: Check Contents of JSON File With JMESPath\n    Given the TestInfra host with URL \"docker://sut\" is ready\n    When the TestInfra file is /tmp/john-smith.json\n    Then the TestInfra JMESPath expression <expression> returns <expected_value>\n    Examples:\n      | expression    | expected_value |\n      | firstName     | John           |\n      | lastName      | Smith          |\n      | age           | 27             |\n      | address.state | NY             |\n      | spouse        | None           |\n```\n\nand `tests/step_defs/test_example.py` contains the following:\n\n```python\n\"\"\"Examples of step definitions for Testinfra BDD feature tests.\"\"\"\nimport testinfra_bdd\nfrom pytest_bdd import given, scenarios\n\nscenarios('../features/example.feature')\n\n\n# Ensure that the PyTest fixtures provided in testinfra-bdd are available to\n# your test suite.\npytest_plugins = testinfra_bdd.PYTEST_MODULES\n\n\n@given('the TestInfra expected value is \"foo\"', target_fixture='expected_value')\ndef the_expected_value_is_foo():\n    \"\"\"\n    The expected value is \"foo\".\n\n    The name and code is up to the user to develop.  However, the target\n    fixture must be called 'expected_value'.\n    \"\"\"\n    return 'foo'\n```\n\n## \"Given\" Steps\n\nGiven steps require that the URL of the system to be tested (SUT) is provided.\nThis URL should comply to the connection string for the [Testinfra connection\nstring](https://testinfra.readthedocs.io/en/latest/backends.html) (e.g.\ndocker://my-host).  Please note that the URL _must_ be enclosed in double\nquotes.\n\nExamples:\n\nTo connect to a Docker container called sut (fail if the target host is\nnot ready):\n\n```gherkin\nGiven the TestInfra host with URL \"docker://java11\" is ready\n```\n\nTo connect to a Docker container called sut but give it 60 seconds to become\nready, use the following:\n\n```gherkin\nGiven the TestInfra host with URL \"docker://sut\" is ready within 60 seconds\n```\n\nIf the host does not become available after 60 seconds, fail the tests.\n\n### Writing a customized \"Given\" Step\n\nIt may be that you may want to create a customized \"Given\" step.  An example\ncould be that the hosts to be tested may be parametrized.  The \"Given\" step\nmust return a target fixture called \"testinfra_bdd_host\" so that the rest of\nthe Testinfra BDD fixtures will function.  This fixture is a instance of the\n`testinfra_bdd.`\n\nThe \"Given\" step should also ascertain that the target host is ready (one\ncan use the `is_host_ready` function for that).\n\nAn example is:\n\n```python\nfrom pytest_bdd import given\nfrom testinfra_bdd import TestinfraBDD\n\n@given('my host is ready', target_fixture='testinfra_bdd_host')\ndef my_host_is_ready():\n    \"\"\"\n    Specify that the target host is a docker container called\n    \"my-host\" and wait up to 60 seconds for the host to be ready.\n    \"\"\"\n    host = TestinfraBDD('docker://my-host')\n    assert host.is_host_ready(60), 'My host is not ready.'\n    return host\n\n...\n```\n\n## \"When\" Steps\n\nWhen steps require that a \"Given\" step has been executed beforehand.  They\nallow the user to either skip tests if the host does not match an expected\nprofile.  They also allow the user to specify which resource or is to be\ntested.\n\n### Skip Tests if Host Profile Does Not Match\n\nIt may be useful to skip tests if you find that the system under test doesn't\nmatch an expected profile (e.g. the system is not debian as expected).  This\ncan be achieved by comparing against the following configurations:\n\n- The OS Type (e.g. linux).\n- The distribution name (e.g. debian).\n- The OS release (e.g. 11).\n- The OS codename if relevant (e.g. bullseye).\n- The host architecture (e.g. x86_64).\n- The hostname (e.g. sut)\n\nExample:\n\n```gherkin\n  Scenario: Skip Tests if Host is Windoze\n    Given the TestInfra host with URL \"docker://sut\" is ready within 10 seconds\n    When the TestInfra system property type is not Windoze skip tests\n```\n\n## Upgrading from 2.Y.Z to 3.0.0\n\nWe introduced a number of breaking changes, namely:\n- A change to the Domain Specific Language (DSL).\n- Moving to TestInfra 9 and dropping support for 6, 7 and 8.\n- Dropping support for EOL versions of Python (3.6, 3.7 and 3.8).\n\nThe changes for the DSL are pretty basic.  We identified a need to namespace\nthe TestInfra tests to stop clashes with other BDD feature code.  If your\nold code looked something like:\n\n```gherkin\n  Scenario: System Package\n    Given the host with URL \"docker://sut\" is ready\n    When the package is ntp\n    Then the package is installed\n```\n\nThen change the code to:\n\n```gherkin\n  Scenario: System Package\n    Given the TestInfra host with URL \"docker://sut\" is ready\n    When the TestInfra package is ntp\n    Then the TestInfra package is installed\n```\n\nAll example code above has been updated to the new format for guidance.\n\n## Upgrading from 1.Y.Z to 2.0.0\n\nWe split the single package into multiple source files.  This means a minor\nbut nonetheless breaking change in your step definitions (all feature files\ncan remain as they are).  The change is how one sets `pytest_plugins`.\n\n### Old Code\n\n```python\npytest_plugins = ['testinfra_bdd']\n```\n\n### New Code\n\n```python\npytest_plugins = testinfra_bdd.PYTEST_MODULES\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "An interface between pytest-bdd and pytest-testinfra.",
    "version": "3.1.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/cbdq-io/testinfra-bdd/issues",
        "Homepage": "https://github.com/cbdq-io/testinfra-bdd"
    },
    "split_keywords": [
        "testinfra",
        " bdd"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3615af629ccd168b7f5fbc14987ee768f876206583b98173811a21df80c50495",
                "md5": "b51d8351e308256d49ede4ec07d826c8",
                "sha256": "86526c5539666d3e79b476197373cffc91c7d142e75dae76b3b5f82338f684cd"
            },
            "downloads": -1,
            "filename": "testinfra_bdd-3.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b51d8351e308256d49ede4ec07d826c8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 22407,
            "upload_time": "2024-12-18T08:57:14",
            "upload_time_iso_8601": "2024-12-18T08:57:14.363823Z",
            "url": "https://files.pythonhosted.org/packages/36/15/af629ccd168b7f5fbc14987ee768f876206583b98173811a21df80c50495/testinfra_bdd-3.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a691485415da368b47b3c68892021e26e5f707526290f3b9a45cf926278b027f",
                "md5": "db54b837515941eb5358e833276acb1b",
                "sha256": "5dd6d696f2dbf2718b1d436f43bd8d01b278eee9ea2a2ae33091a365433aaee4"
            },
            "downloads": -1,
            "filename": "testinfra_bdd-3.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "db54b837515941eb5358e833276acb1b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 20847,
            "upload_time": "2024-12-18T08:57:16",
            "upload_time_iso_8601": "2024-12-18T08:57:16.663566Z",
            "url": "https://files.pythonhosted.org/packages/a6/91/485415da368b47b3c68892021e26e5f707526290f3b9a45cf926278b027f/testinfra_bdd-3.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-18 08:57:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cbdq-io",
    "github_project": "testinfra-bdd",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "bandit",
            "specs": [
                [
                    "==",
                    "1.7.10"
                ]
            ]
        },
        {
            "name": "build",
            "specs": [
                [
                    "==",
                    "1.2.2.post1"
                ]
            ]
        },
        {
            "name": "colorama",
            "specs": [
                [
                    "==",
                    "0.4.6"
                ]
            ]
        },
        {
            "name": "coverage",
            "specs": [
                [
                    "==",
                    "7.6.2"
                ]
            ]
        },
        {
            "name": "exceptiongroup",
            "specs": [
                [
                    "==",
                    "1.2.2"
                ]
            ]
        },
        {
            "name": "flake8",
            "specs": [
                [
                    "==",
                    "7.1.1"
                ]
            ]
        },
        {
            "name": "flake8-docstrings",
            "specs": [
                [
                    "==",
                    "1.7.0"
                ]
            ]
        },
        {
            "name": "flake8-quotes",
            "specs": [
                [
                    "==",
                    "3.4.0"
                ]
            ]
        },
        {
            "name": "gitchangelog",
            "specs": [
                [
                    "==",
                    "3.0.4"
                ]
            ]
        },
        {
            "name": "gitdb",
            "specs": [
                [
                    "==",
                    "4.0.11"
                ]
            ]
        },
        {
            "name": "GitPython",
            "specs": [
                [
                    "==",
                    "3.1.43"
                ]
            ]
        },
        {
            "name": "iniconfig",
            "specs": [
                [
                    "==",
                    "2.0.0"
                ]
            ]
        },
        {
            "name": "isort",
            "specs": [
                [
                    "==",
                    "5.13.2"
                ]
            ]
        },
        {
            "name": "jmespath",
            "specs": [
                [
                    "==",
                    "1.0.1"
                ]
            ]
        },
        {
            "name": "Mako",
            "specs": [
                [
                    "==",
                    "1.3.5"
                ]
            ]
        },
        {
            "name": "mando",
            "specs": [
                [
                    "==",
                    "0.7.1"
                ]
            ]
        },
        {
            "name": "markdown-it-py",
            "specs": [
                [
                    "==",
                    "3.0.0"
                ]
            ]
        },
        {
            "name": "MarkupSafe",
            "specs": [
                [
                    "==",
                    "3.0.1"
                ]
            ]
        },
        {
            "name": "mccabe",
            "specs": [
                [
                    "==",
                    "0.7.0"
                ]
            ]
        },
        {
            "name": "mdurl",
            "specs": [
                [
                    "==",
                    "0.1.2"
                ]
            ]
        },
        {
            "name": "packaging",
            "specs": [
                [
                    "==",
                    "24.1"
                ]
            ]
        },
        {
            "name": "parse",
            "specs": [
                [
                    "==",
                    "1.20.2"
                ]
            ]
        },
        {
            "name": "parse_type",
            "specs": [
                [
                    "==",
                    "0.6.4"
                ]
            ]
        },
        {
            "name": "pathspec",
            "specs": [
                [
                    "==",
                    "0.12.1"
                ]
            ]
        },
        {
            "name": "pbr",
            "specs": [
                [
                    "==",
                    "6.1.0"
                ]
            ]
        },
        {
            "name": "pluggy",
            "specs": [
                [
                    "==",
                    "1.5.0"
                ]
            ]
        },
        {
            "name": "pycodestyle",
            "specs": [
                [
                    "==",
                    "2.12.1"
                ]
            ]
        },
        {
            "name": "pydocstyle",
            "specs": [
                [
                    "==",
                    "6.3.0"
                ]
            ]
        },
        {
            "name": "pyflakes",
            "specs": [
                [
                    "==",
                    "3.2.0"
                ]
            ]
        },
        {
            "name": "Pygments",
            "specs": [
                [
                    "==",
                    "2.18.0"
                ]
            ]
        },
        {
            "name": "pyproject_hooks",
            "specs": [
                [
                    "==",
                    "1.2.0"
                ]
            ]
        },
        {
            "name": "pystache",
            "specs": [
                [
                    "==",
                    "0.6.5"
                ]
            ]
        },
        {
            "name": "pytest",
            "specs": [
                [
                    "==",
                    "8.3.3"
                ]
            ]
        },
        {
            "name": "pytest-bdd",
            "specs": [
                [
                    "==",
                    "7.3.0"
                ]
            ]
        },
        {
            "name": "pytest-cov",
            "specs": [
                [
                    "==",
                    "5.0.0"
                ]
            ]
        },
        {
            "name": "pytest-testinfra",
            "specs": [
                [
                    "==",
                    "10.1.1"
                ]
            ]
        },
        {
            "name": "PyYAML",
            "specs": [
                [
                    "==",
                    "6.0.2"
                ]
            ]
        },
        {
            "name": "radon",
            "specs": [
                [
                    "==",
                    "6.0.1"
                ]
            ]
        },
        {
            "name": "rich",
            "specs": [
                [
                    "==",
                    "13.9.2"
                ]
            ]
        },
        {
            "name": "setuptools",
            "specs": [
                [
                    "==",
                    "75.1.0"
                ]
            ]
        },
        {
            "name": "six",
            "specs": [
                [
                    "==",
                    "1.16.0"
                ]
            ]
        },
        {
            "name": "smmap",
            "specs": [
                [
                    "==",
                    "5.0.1"
                ]
            ]
        },
        {
            "name": "snowballstemmer",
            "specs": [
                [
                    "==",
                    "2.2.0"
                ]
            ]
        },
        {
            "name": "stevedore",
            "specs": [
                [
                    "==",
                    "5.3.0"
                ]
            ]
        },
        {
            "name": "tomli",
            "specs": [
                [
                    "==",
                    "2.0.2"
                ]
            ]
        },
        {
            "name": "typing_extensions",
            "specs": [
                [
                    "==",
                    "4.12.2"
                ]
            ]
        },
        {
            "name": "urllib3",
            "specs": [
                [
                    "==",
                    "2.2.3"
                ]
            ]
        },
        {
            "name": "wheel",
            "specs": [
                [
                    "==",
                    "0.44.0"
                ]
            ]
        },
        {
            "name": "yamllint",
            "specs": [
                [
                    "==",
                    "1.35.1"
                ]
            ]
        }
    ],
    "lcname": "testinfra-bdd"
}
        
Elapsed time: 0.53519s