Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving of _factory doesn't apear, if run few test at once #1054

Open
mihalt opened this issue Mar 24, 2023 · 0 comments
Open

Saving of _factory doesn't apear, if run few test at once #1054

mihalt opened this issue Mar 24, 2023 · 0 comments

Comments

@mihalt
Copy link

mihalt commented Mar 24, 2023

Hi! I fetched strange behaviour, most probably the bag, that I resolved, but it shouldn't be. That you can see under a comments

@pytest.fixture()
def hundred_provider_stocks(provider_stock_factory):
    provider_stock_factory.create_batch(10)


@pytest.mark.django_db
@pytest.mark.parametrize('browser', [lazy_fixture("partner_browser_client"), lazy_fixture("client")])
@pytest.mark.parametrize('page', [('products-detail', [1]), ('products-list', [])])
def test_get_serializer_class(browser, page, hundred_provider_stocks):
    page = browser.get(reverse(page[0], args=page[1]))
    assert page.status_code == 200


@pytest.mark.django_db(transaction=True)
def test_notify_about_providerstock_change(provider_stock_factory, demand_factory, personal_subscription_factory,
                                           product, mailoutbox, celery_worker):
    d = demand_factory(individual_demands=[product])
    personal_subscription_factory(demand=d)
    p = provider_stock_factory(product=product)
    p.save() # If I don't type this, mail, that should be sent each time, when object is changing, is not sending, if I run all test at one time in module. So I have only 1 mail in my mailoutbox. But it works good if I run only test_notify_about_providerstock_change. 
    p.price = 1000
    p.save()
    logging.info(mailoutbox[0].body)
    assert len(mailoutbox) == 2

And second question is that I wanted to do @pytest.fixture(scope="session" or "module") on hundred_provider_stocks but I got error

ScopeMismatch: You tried to access the function scoped fixture provider_stock_factory with a module scoped request object, involved factories:
goods\test_app.py:13:  def hundred_provider_stocks(provider_stock_factory)
venv\lib\site-packages\pytest_factoryboy\fixture.py:493:  def fn(request: 'SubRequest', *, factory_class: 'F' = <class 'keysbilling.factoryboy_fixtures.ProviderStockFactory'>) -> 'F'

This solution doesn't work for me
https://stackoverflow.com/questions/51783757/pytest-scopemismatch-error-how-to-use-fixtures-properly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant