pytest-django
pytest-django copied to clipboard
Saving of _factory doesn't apear, if run few test at once
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