What is Fixture in PyTest?

HOME

import pytest

@pytest.fixture()
def setup():
    print("This will be executed before any test")


def test_fixture(setup):
    print("This is the fixture main method")

import pytest


@pytest.fixture()
def setup():
    print("This will be executed before any test")
    yield
    print("This will be executed after any test")


def test_fixture(setup):
    print("This is the fixture main method")