Code Monkey home page Code Monkey logo

Comments (6)

nathanielobrown avatar nathanielobrown commented on May 30, 2024 4

@olegpidsadnyi, this would be useful for another simple (but important) reason. You cannot use a factory in a fixture with scope other than function. If you do, you get an error like You tried to access the 'function' scoped fixture 'factory' with a 'class' scoped request object.

I think it would be best to give people the option. If they are messing with scopes, ideally they understand what they are doing and the potential foot-guns that come with that.

Not a big deal as we can always use the factory directly in these cases, but would be nice to have this.

from pytest-factoryboy.

NeveHanter avatar NeveHanter commented on May 30, 2024 2

Hey @olegpidsadnyi

I also want to suggest this change, in my case I have thousand of tests, nearly all of them need to create base DB structure consisting of approx. 60 db objects and because of the function scope each test creates these objects over and over only to delete them after the each of the tests completes.

Other case includes that each test case class have some objects which are common to each of it's test methods, so again we're creating same db objects and again we're deleting them between the tests.

from pytest-factoryboy.

olegpidsadnyi avatar olegpidsadnyi commented on May 30, 2024

currently not supported. I was never using model fixtures with the session scope because the entities of the data model are changed frequently.
For example author is not just one per your testing suite, right?
It is better for the test isolation to create new parents for every test.

Can you give me an example when author can be one for the whole session?

from pytest-factoryboy.

olegpidsadnyi avatar olegpidsadnyi commented on May 30, 2024

@NeveHanter We are not deleting the objects from our database and it is huge. This also improves your tests in terms of isolation, so that you don't get false positives or irrelevant items don't appear in collections.
I'm not also sure if you can register some fixtures as session scoped. Can session scoped fixture depend on non-session scoped? In case of relationships you can easily configure such inconsistent dependencies.

from pytest-factoryboy.

czwartaoslpoj avatar czwartaoslpoj commented on May 30, 2024

I'm quite surprised it is still not supported. I'm migrating Django project from unittest to pytest framework and this is big disadvantage. With big projects when you have factories that have subfactories that have subfactories, tests are slowing down drastically...

from pytest-factoryboy.

youtux avatar youtux commented on May 30, 2024

I think we can have this feature, but unfortunately, neither @olegpidsadnyi nor I have much spare time to address this.
Feel free to open a PR.

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.