Skip to main content
PyPI version Python versions See Build Status on GitHub Actions

pytest-himark is a plugin that creates markers from a json configuration to filter pytest’s test collection.


This pytest plugin was generated with Cookiecutter along with @hackebrot’s cookiecutter-pytest-plugin template.

Requirements

  • json >= 2.0.9

Installation

You can install “pytest-himark” via pip from PyPI:

$ pip install pytest-himark

Usage

After installing this plugin, pytest will automatically load it when launching tests. You will simply need to add the –json option to the command line with the path to the json containing the markers you want to enable. Alternatively, you can add the –json option and the path in the pytest.ini directly, in the addopts variable.

  • In pytest.ini:

    addopts = --json=path/to/my/config.json
  • Or by command line:

    >> pytest --json=path/to/my/config.json

The markers can be configured in 4 ways to give more flexibility to the end user. The first way is having a ‘markers’ key containing a dictionary with the name of the markers as key, and a boolean as value. If the boolean is true, the marker with the specified name will be created.

Example:

{
    'markers': {
        'marker1': true,
        'marker2': true,
        'marker3': false,
        'marker4': false
    }
}

This json will result in the following marker filtering:

-m '(marker1 or marker2)'

Another way of specifying marker is to define a ‘devices’ key, with a list of dictionaries as value. Each key from the ‘devices’ list can be refered to as a ‘device’ and should contain a key named ‘name’ as a string and a key named ‘used’ as a boolean. If the ‘used’ key of a device is set to true, a marker will be created and named with the ‘name’ string.

Example:

{
    'devices': [
         {
            'name': "device1",
            'used': true,
         },
         {
            'name': "device2",
            'used': false,
         }
    ]
}

This json will result in the following marker filtering:

-m '(device1)'

Another way to specifying marker is to have a key named ‘type’ in a device-specific dictionary (see above), defined as a string. A marker with the string value of the ‘type’ will be created.

Example:

{
    'devices': [
         {
            'name': "device1",
            'type': "my_type"
            'used': true,
         },
         {
            'name': "device2",
            'used': false,
         }
    ]
}

This json will result in the following marker filtering:

-m '(device1 or my_type)'

One last way to specifying marker is to have keys named ‘do’, ‘di’ and/or ‘ai’ in a device-specific dictionary (see above), defined as list of strings. A marker will be created for every string in those arrays.

Example:

{
    'devices': [
        {
            "name": "device1",
            "do": [
                "do1"
            ],
            "di": [
                "di1"
            ],
            "ai": [
                "ai1"
            ],
            "used": true,
         }
        {
            "name": "device2",
            "used": false,
         }
    ]
}

This json will result in the following marker filtering:

-m '(device1 or do1 or di1 or ai1)'

Launching pytest now will then automatically add the filter to the command line, e.g.:

>> pytest -m '(device1 or do1 or di1 or ai1)'

Finally, after pytest test collection has completed, this plugin will also filter out any test that is marked with an undefined marker. For example consider the following config:

{
    'markers': {
        'marker1': true
    }
}

And the following test:

@pytest.mark.marker1
@pytest.mark.marker2
def test_mytest():
    assert True

This test is marked with marker1 which is defined in the configuration, but also with marker2 which is not. Therefore, despite being initially collected by pytest, this plugin will remove it from the selection.

Note that any empty string as marker will be ignored by the plugin, and any leading or trailing spaces will be removed.

Contributing

Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.

License

Distributed under the terms of the MIT license, “pytest-himark” is free and open source software

Issues

If you encounter any problems, please file an issue along with a detailed description.

Release files for pytest-himark 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-himark 0.2.3
File Size Uploaded
pytest_himark-0.2.3.tar.gz 7.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-himark 0.2.3
File Interpreter ABI Platform
pytest_himark-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 14.0 kB

Release files / pytest_himark-0.2.3.tar.gz

Download URL pytest_himark-0.2.3.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
9cae33b6864cbec4befcf1d5356499437985bb59b141c4e75b49ea522841aac3
BLAKE2b-256 checksum
How to use checksums
a8dbf2b7d3f62688514aff3da9650c37ca3b4df566d1484962e4e03ba6ca22ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.0

Release files / pytest_himark-0.2.3-py3-none-any.whl

Download URL pytest_himark-0.2.3-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ae18618dc18e9041515e759f1acadeeeee57ee1472704d1f2cb3ea258c28804b
BLAKE2b-256 checksum
How to use checksums
6f827b78ce0d85d16fd64be79d90b824f1dab58d502df3665d5c06f8d7c6612b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.0

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page