File size: 780 Bytes
6bd44d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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