question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to use this with FactoryBoy?

See original GitHub issue

It would be useful to see an example of how to use pytest-flask-sqlalchemy with FactoryBoy/pytest-factoryboy, if they can work together. For example, I’m not clear what would be used for factory classes’ sqlalchemy_session field.

(Background: I use something like pytest-flask-sqlalchemy in my tests, and would like to switch to pytest-flask-sqlalchemy when the MySQL PR is included, and would also like to use FactoryBoy, but have never managed to get the two things to work well together.)

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:17 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
layoastercommented, Apr 10, 2019

@philgyford when a fixture needs anothers fixture you just pass them via paremeters so your fixture book_factory should look like this:

@pytest.fixture
def book_factory(db_session, author_factory):

    class BookFactory(factory.alchemy.SQLAlchemyModelFactory):

        class Meta:
            model = Book
            sqlalchemy_session = db_session
            sqlalchemy_session_persistence = "commit"

        title = factory.Faker("sentence", nb_words=4)
        author = factory.SubFactory(author_factory)

    return BookFactory
2reactions
killthekittencommented, Mar 5, 2019

A reproducible example of your setup would help. We use FactoryBoy with pytest-flask-sqlalchemy + postgres without any troubles.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using factory_boy with ORMs - Read the Docs
This feature makes it possible to use SubFactory to create embedded document. A minimalist example: import mongoengine class Address(mongoengine.
Read more >
Common recipes — Factory Boy stable documentation
Most recipes below take on Django model examples, but can also be used on their own. ... It is also possible to reset...
Read more >
factory_boy — Factory Boy stable documentation
factory_boy is designed to work well with various ORMs (Django, MongoDB, SQLAlchemy), and can easily be extended for other libraries. Its main features...
Read more >
Reference — Factory Boy stable documentation
Use this attribute to change the strategy used by a Factory . The default is CREATE_STRATEGY . Attributes and methods . class...
Read more >
Introduction — Factory Boy stable documentation
Users looking for quick helpers may take a look at Common recipes, ... It is also possible to override the defined attributes by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found