Skip to content

Dynamically requested fixture missing in request.fixturenames #3959

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

Closed
blueyed opened this issue Sep 8, 2018 · 0 comments
Closed

Dynamically requested fixture missing in request.fixturenames #3959

blueyed opened this issue Sep 8, 2018 · 0 comments
Labels
topic: fixtures anything involving fixtures directly or indirectly

Comments

@blueyed
Copy link
Contributor

blueyed commented Sep 8, 2018

Dynamically requesting a fixture via some autouse fixture does not add it to request.fixturenames:

import pytest


dynamic_called = False


@pytest.fixture()
def dynamic():
    global dynamic_called
    dynamic_called = True


@pytest.fixture(autouse=True)
def autouse(request):
    request.getfixturevalue('dynamic')


def test_foo(request):
    assert dynamic_called
    assert 'dynamic' in request.fixturenames
Test session starts (platform: linux, Python 3.6.6, pytest 3.7.3, pytest-sugar 0.9.1)
Django settings: foo.settings (from environment variable)
Using --randomly-seed=1536427658
rootdir: /project, inifile: setup.cfg
plugins: django-3.4.2.dev4+g37723ff.d20180908, requests-mock-1.5.2, testmon-0.9.13, repeat-0.6.0, randomly-1.2.3, pdb-0.3.1, mock-1.10.0, forked-0.2, cov-2.5.1, asyncio-0.9.0, celery-4.2.1,
xdist-1.22.6.dev1+g96af694.d20180828, sugar-0.9.1


―――――――――――――――――――――――――――――――――――――――――― test_foo ――――――――――――――――――――――――――――――――――――――――――
tests/test_querycount.py:18: in test_foo
    assert 'dynamic' in request.fixturenames
E   AssertionError: assert 'dynamic' in ['_fail_for_invalid_template_variable', 'django_test_environment', 'django_db_blocker', '_django_setup_unittest', '_dj_autoclear_mailbox', '_django_clear_site_cache', ...]
E    +  where ['_fail_for_invalid_template_variable', 'django_test_environment', 'django_db_blocker', '_django_setup_unittest', '_dj_autoclear_mailbox', '_django_clear_site_cache', ...] = <FixtureRequest for <Function 'test_foo'>>.fixturenames

I've noticed this with pytest-django, which uses an autouse fixture to handle the django_db mark.

@Zac-HD Zac-HD added the topic: fixtures anything involving fixtures directly or indirectly label Oct 20, 2018
@blueyed blueyed closed this as completed Nov 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: fixtures anything involving fixtures directly or indirectly
Projects
None yet
Development

No branches or pull requests

2 participants