pytest fixture not found (tested)

fixture 'x' not found means no fixture with that name is visible to the test. Shared fixtures must live in a conftest.py in the test's directory or a parent (not in another test file or a sibling folder), and plugin fixtures like mocker need the plugin installed in the same interpreter.

pytest matches each test argument to a fixture by name, looking only in the test's own module, the conftest.py files in its directory and parent directories, and installed plugins. Anything else gives fixture 'x' not found as an ERROR at setup. Each cause below was reproduced on pytest 9.1.1 in a clean virtualenv.

1. A typo: read the "available fixtures" list

$ cat test_a.py
import pytest

@pytest.fixture
def client():
    return "c"

def test_get(clinet):
    assert clinet
$ pytest -q | sed -n "3,9p"
__________________________ ERROR at setup of test_get __________________________
file /tmp/fx384/a/test_a.py, line 7
  def test_get(clinet):
E       fixture 'clinet' not found
>       available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, capteesys, client, doctest_namespace, monkeypatch, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, subtests, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
>       use 'pytest --fixtures [testpath]' for help on them.

The error lists every fixture visible to that test. If yours is there under a slightly different name (client vs clinet), it is a typo. If it is missing from the list, pytest cannot see it: one of the causes below.

2. Fixture defined in another test file

$ find tests -name "*.py" | sort
tests/test_one.py
tests/test_two.py
$ cat tests/test_two.py
def test_two(db):
    assert db == {}
$ pytest -q | tail -3
=========================== short test summary info ============================
ERROR tests/test_two.py::test_two
1 passed, 1 error in 0.01s

A fixture defined in test_one.py is only visible inside test_one.py. Importing it with from test_one import db happens to work but is fragile: linters see the import as unused or redefined, and from test_one import * also imports test_one's tests, so they run twice (3 passed instead of 2 in our run). Move shared fixtures to conftest.py; pytest loads it automatically, no import needed:

$ find tests -name "*.py" | sort
tests/conftest.py
tests/test_one.py
tests/test_two.py
$ cat tests/conftest.py
import pytest

@pytest.fixture
def db():
    return {}
$ pytest -q | tail -1
2 passed in 0.01s

3. conftest.py in the wrong directory

$ find tests -name "*.py" | sort
tests/api/conftest.py
tests/ui/test_ui.py
$ pytest -q | grep "not found"
E       fixture 'token' not found

A conftest.py applies to its own directory and everything below it, never to sibling directories. tests/api/conftest.py is invisible to tests/ui/. Move it up to the common parent:

$ find tests -name "*.py" | sort
tests/api/test_api.py
tests/conftest.py
tests/ui/test_ui.py
$ pytest -q | tail -1
2 passed in 0.01s

To check what a given path can see, run pytest --fixtures on it; it also prints where each fixture is defined:

$ pytest --fixtures -q tests/ui | grep -c "^token"
0
$ pytest --fixtures -q tests/api | grep -A1 "^token"
token -- tests/api/conftest.py:4
    no docstring available

4. Fixture from a plugin that is not installed (mocker, client, event_loop...)

$ cat test_d.py
def test_m(mocker):
    mocker.patch("os.getcwd", return_value="/x")
$ pytest -q | grep "not found"
E       fixture 'mocker' not found
$ pip install -q pytest-mock 2>/dev/null; echo installed
installed
$ pytest -q | tail -1
1 passed in 0.00s

mocker comes from pytest-mock, benchmark from pytest-benchmark, Django's client/db from pytest-django, Flask's client from pytest-flask or your own conftest. Install the plugin in the same interpreter that runs pytest (python -m pip install ... then python -m pytest); a plugin installed in another virtualenv gives exactly this error.

5. fixture 'self' not found

$ cat test_f.py
def test_total(self):
    assert 1 + 1 == 2
$ pytest -q | grep "not found"
E       fixture 'self' not found

A module-level function with a self parameter: pytest treats self as a fixture name. Either remove self or put the function inside a class Test...:.

6. unittest.TestCase methods cannot take fixtures

$ cat test_e.py
import unittest, pytest

@pytest.fixture
def num():
    return 1

class T(unittest.TestCase):
    def test_x(self, num):
        assert num == 1
$ pytest -q | grep "^E "; pytest -q | tail -1
E       TypeError: T.test_x() missing 1 required positional argument: 'num'
1 failed in 0.04s

Inside a unittest.TestCase subclass pytest does not inject fixture arguments, so the error is a TypeError: missing 1 required positional argument rather than "fixture not found". Use @pytest.mark.usefixtures (or an autouse fixture) and pass data through request.cls, or convert the class to a plain pytest class:

$ cat test_e.py
import unittest, pytest

@pytest.fixture
def num(request):
    request.cls.num = 1

@pytest.mark.usefixtures("num")
class T(unittest.TestCase):
    def test_x(self):
        assert self.num == 1
$ pytest -q | tail -1
1 passed in 0.00s

Checklist

Related: pytest error vs failure (ERROR at setup), pytest exit codes.

Frequently asked questions

Why is my fixture not found from another test file?

Fixtures defined in a test module are only visible in that module. Move shared fixtures to conftest.py in the same or a parent directory.

Why does pytest say fixture 'mocker' not found?

mocker comes from the pytest-mock plugin. Install it with python -m pip install pytest-mock in the environment that runs pytest.

What does fixture 'self' not found mean?

A test function outside a class has a self parameter. Remove self or move the function into a Test class.

Written with AI assistance. Measured on 2026-10-23 with pytest 9.1.1 (and pytest-mock for block 4) on Python 3.13.5 in a clean virtualenv. Each block was run verbatim and the output pasted unedited. PlainHeaders is our extension; Python and pytest are free.