I'm trying to use PyTest and I cannot obtain how to set fixtures. I've tried the following code:
import pytest
import random
@pytest.fixture()
def setup():
a = random.randint(0, 10)
def test(setup):
assert 3 > a
if __name__ == '__main__':
pytest.main()
And I am getting "NameError: name 'a' is not defined".
Also the example from the official documentation doesn't work. What's wrong? I need functionality similar to setUp/tearDown. But I don't want to use unittest. Can someone provide me an example with working fixtures (both setUp type and tearDown type)?
I want to write some test as functions and some test as methods inside classes. Therefore me second question is for an working example of using fixture with classes/methods. I just need to see working examples of fixtures in Python.
Is there a different Python 3 unit testing framework with assertions as simple as in PyTest?