jeudi 27 août 2015

Mark test as skipped from pytest_collection_modifyitems

how can i mark a test as skipped in pytest collection process.

What im trying to do is have pytest collect all tests and then using the pytest_collection_modifyitems hook mark a certain test as skipped according to a condition i get from a database.

I found a solution which i don't like, I was wondering if maybe there is a better way.

def pytest_collection_modifyitems(items, config):
    ... # get skip condition from database
    for item in items:
        if skip_condition == True:
            item._request.applymarker(pytest.mark.skipif(True, reason='Put any reason here'))

The problem with this solution is I'm accessing a protected member (_request) of the class..

Thanks.

Aucun commentaire:

Enregistrer un commentaire