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.

scope of fixtures created by register()?

See original GitHub issue

when 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:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
nathanielobrowncommented, Feb 20, 2021

@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.

2reactions
NeveHantercommented, May 16, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

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