I installed pytest-django
with pip and made a test file, which uses the client
fixture as per the docs, but running this gives me fixture 'client' not found
. Here's my test_homepage.py
:
import pytest
@pytest.mark.django_db
def test_homepage(client):
response = client.get('/')
assert response.status_code == 200
Are you sure you have pytest-django
installed. I installed pytest-django
on my machine and ran a simple project.
pip install pytest-django
Setup and run my sample test:
platform linux -- Python 3.4.3 -- py-1.4.30 -- pytest-2.7.2
rootdir: /home/matt/projects/test_app/src, inifile: pytest.ini
plugins: django
collected 1 items
tests/test_example.py .
Sample code:
import pytest
@pytest.mark.django_db
def test_something(client):
response = client.get('/')
assert response.status_code == 200
Note the plugins listed and the code works.
Uninstall for the sake of testing I am going to remove pip uninstall pytest-django
Once again run the tests py.test
platform linux -- Python 3.4.3 -- py-1.4.30 -- pytest-2.7.2
rootdir: /home/matt/projects/test_app/src, inifile: pytest.ini
collected 1 items
tests/test_example.py E
==================================== ERRORS ====================================
_______________________ ERROR at setup of test_something _______________________
file /home/matt/projects/test_app/src/tests/test_example.py, line 3
@pytest.mark.django_db
def test_something(client):
fixture 'client' not found
available fixtures: tmpdir, pytestconfig, recwarn, capsys, capfd, monkeypatch
use 'py.test --fixtures [testpath]' for help on them.
Now we can see the same error you are stating in your project.
So, if I were you I would completely remove pytest
and pytest-django
from your environment then re-install. It looks like either pytest-django
has not been installed or that the plugins are not being detected for some reason.
If this does not help solve the project your other option is to run py.test --traceconfig
this will give you a more verbose output of the run process. Do this then add the output to your question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With