markers.uncollect module


Used internally to mark a test to be “uncollected”

This mark should be used at any point before or during test collection to dynamically flag a test to be removed from the list of collected tests.

py.test adds marks to test items a few different ways. When marking in a py.test hook that takes an Item or Node (Item is a subclass of Node), use item.add_marker('uncollect') or item.add_marker(pytest.mark.uncollect)

When dealing with the test function directly, using the mark decorator is preferred. In this case, either decorate a test function directly (and have a good argument ready for adding a test that won’t run...), e.g. @pytest.mark.uncollect before the test def, or instantiate the mark decorator and use it to wrap a test function, e.g. pytest.mark.uncollect()(test_function)


The uncollectif marker is very special and can cause harm to innocent kittens if used incorrectly. The uncollectif marker enables the ability to uncollect a specific test if a certain condition is evaluated to True. The following is an example:

@pytest.mark.uncollectif(lambda: version.current_version() < '5.3')

In this case, when pytest runs the modify items hook, it will evaluate the lambda function and if it results in True, then the test will be uncollected. Fixtures that are generated by testgen, such as provider_key, provider_data etc, are also usable inside the collectif marker, assuming the fixture name is also a prerequisite for the test itself. For example:: python

@pytest.mark.uncollectif(lambda provider_type: provider_type != 'virtualcenter')
def test_delete_all_snapshots(test_vm, provider_key, provider_type):

Here, the fixture provider_type is special as it comes from testgen and is passed to the lambda for comparison.


Be aware, that this cannot be used for any other fixture types. Doing so will break pytest and may invalidate your puppies.

markers.uncollect.pytest_collection_modifyitems(session, config, items)[source]

Evaluates if an item should be uncollected

Tests markers against a supplied lambda from the marker object to determine if the item should be uncollected or not.