scope of fixtures created by register()?
See original GitHub issuewhen I do
register(AuthorFactory)
it creates fixture author_factory
my question is how can I specify a scope='session'
to the fixture ?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to use fixtures — pytest documentation
Fixture scopes Fixtures are created when first requested by a test, and are destroyed based on their scope : function : the...
Read more >Understand 5 Scopes of Pytest Fixtures | by Xiaoxu Gao
Five different scopes of fixtures control how often each fixture will be executed. The higher scope the fixture has, the earlier the fixture...
Read more >pytest fixtures: explicit, modular, scalable
Fixture functions are registered by marking them with @pytest.fixture . Let's look at a simple ... SMTP() instance created by the fixture function....
Read more >What are the different Fixture Scopes in Pytest - Edureka
Module: If the Module scope is defined, the fixture will be created/invoked only once per module. · Class: With Class scope, one fixture...
Read more >how to share a session object created in fixture having scope ...
A fixture can use other fixture too. That means you can use a session fixture inside a module fixture, you can use a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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 likeYou 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.
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.