Skip to content

Dynamically requested fixture missing in request.fixturenames #3959

@blueyed

Description

@blueyed

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: fixturesanything involving fixtures directly or indirectly

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions