Code Monkey home page Code Monkey logo

Comments (9)

bubenkoff avatar bubenkoff commented on May 31, 2024

can't you just use autouse fixture for that?
and then separate db related tests via package so then fixture will be used only for tests using it

from pytest-factoryboy.

underyx avatar underyx commented on May 31, 2024

@bubenkoff I was thinking of trying it but

  1. I'm worried about the order, is it guaranteed to run first?
  2. I'm not sure how viable the package separation is, we have a few beastly functions which access up to five databases.

from pytest-factoryboy.

bubenkoff avatar bubenkoff commented on May 31, 2024

to be sure about the order you do need to explicitly declare that - i agree, so avoiding it is better
but autouse fixtures always go before the explicitly used ones

from pytest-factoryboy.

olegpidsadnyi avatar olegpidsadnyi commented on May 31, 2024

@underyx What kind of the base class are you using for your factories?
I'm using SQLAlchemy, so it is lazily bound to the same session maker that my test setup is using.

In what way your factory is storing the model? Basically what ORM are you using?

from pytest-factoryboy.

bubenkoff avatar bubenkoff commented on May 31, 2024

@underyx this doesn't look like very big overhead

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

if db is session also scoped, then making it autouse is efficient

from pytest-factoryboy.

underyx avatar underyx commented on May 31, 2024

@underyx What kind of the base class are you using for your factories?

@olegpidsadnyi: factory.alchemy.SQLAlchemyModelFactory

I'm using SQLAlchemy as well — the factories.Session in the issue description's code is an SQLAlchemy scoped_session.

from pytest-factoryboy.

bubenkoff avatar bubenkoff commented on May 31, 2024

@underyx doing models.metadata.create_all(engine) on every test if very inefficient
i would invest time in making tests isolated still, but sharing the same database during the whole session.
The way we do it is normally via randomization, using https://pypi.python.org/pypi/Faker
there's a plugin as well for it's integration pytest-faker

from pytest-factoryboy.

underyx avatar underyx commented on May 31, 2024

@bubenkoff well, alright, we have everything configured now with autouse=True and it works. But it's still not ideal that any test run will automatically create all databases even when I run tests that don't need any database at all. Any chance of this feature making it into pytest-factoryboy?

from pytest-factoryboy.

olegpidsadnyi avatar olegpidsadnyi commented on May 31, 2024

@underyx At this point I don't see it is coming. It would be yet another magical point of declaring a dependency besides a factory class, fixture registration (partial specialization), fixture propagation via conftest.py and finally the @pytest.mark.parametrize.
This would be just an invitation to start abusing it when there are decent ways to configure the test suite.

from pytest-factoryboy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.