import pytest from my_app.models import FooModel, BarModel @pytest.fixture def foo_model(): """Fixture function para crear una instancia de FooModel""" yield FooModel() @pytest.fixture def bar_model(): """Fixture function para crear una instancia de BarModel""" yield BarModel() @pytest.fixture(scope="session") def db_connection(): """Fixture function para crear una conexión a la base de datos""" connection = create_database_connection() yield connection close_database_connection(connection) def test_something(foo_model, bar_model, db_connection): # Prueba que usa las fixture functions assert foo_model.do_something() == bar_model.do_something() assert db_connection.execute("SELECT COUNT(*) FROM tabla").fetchone()[0] > 0