lundi 10 février 2020

Update and share variable between tests on Pytest

So, I'm running some tests that each one of them creates a variable (key), like:

def test_123():
    key = 'abc'
    ....
    ---- test_123 PASSED! ----

def test_456():
    key = 'def'
    ....
    ---- test_456 FAILED! ----

def check_keys():
    # keys = ['abc']
    for key in keys:
    ....

And I have another test, last to be executed, with the purpose of verify those keys. But it should verify only the keys whose test has passed.

So, I'm planning to create a list that should be a global variable between those tests, and increment it with the proper key when the given test passes.

And the last test should go through this list and check the keys of the tests that passed.

I have read about pytest hooks and pytest cache but the examples that I found were too complicated :(

Someone can help me? Thanks!

Aucun commentaire:

Enregistrer un commentaire