Skip to content

Allow passing fixtures that pytest-factory's fixtures should depend on #37

@underyx

Description

@underyx

I have the following fixtures:

@pytest.yield_fixture(scope='session')
def db_url():
    with testing.postgresql.Postgresql() as db:
        yield db.url()


@pytest.yield_fixture
def db(db_url):
    """Create a database session."""
    engine = sqlalchemy.create_engine(db_url)

    models.metadata.create_all(engine)

    factories.Session.configure(bind=engine)
    session = factories.Session()  # creates the thread local session used by factories
    yield session
    session.rollback()
    factories.Session.remove()  # disables the thread local session

    models.metadata.drop_all(engine)


pytest_factoryboy.register(factories.BookFactory)

My problem now is that trying to use the book_factory fixture on its own doesn't work; I need the db fixture to open a session the factory can use, first.

I'd like to be able to specify something like

pytest_factoryboy.register(factories.BookFactory, depends_on=['db'])

which would have the same effect as the manual implementation of

def book_factory(db):
    # …

would.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions