13π
I found out what was the reason for my problem.
I just uninstall
django-pytest 0.2.0
and install
pytest-django
instead by running the following command
pip install pytest-django
and run the following command after pip installed pytest-django
set DJANGO_SETTINGS_MODULE=testing.settings
And everything just works fine.
9π
The accepted answer itβs not answering OP question neither providing solution.
I have encountered the same problem, Iβm using Django 4.0 and Pytest 7.2.1
Iβm using pytest.ini as configuration file.
Solution:
[tool:pytest]
DJANGO_SETTINGS_MODULE = core.settings.local
python_files = test_*.py
Adding keyword tool solves the problem.
Another thing that might be necessary is adding ENV variable:
export DJANGO_SETTINGS_MODULE=mysite.settings
- How to read sql query to pandas dataframe / python / django
- What are the disadvantages of using AWS ELB directly with Gunicorn (no nginx)?
3π
The warning
PytestConfigWarning: Unknown config option: some-name
means that the config option some-name
is not known to pytest
or any of the currently installed pytest
plugins (just what the warning implies). In particular, here it means that either pytest-django
is not installed, or it is not visible to pytest
for some reason (e.g. you have installed pytest-django
using the wrong pip
command).
To troubleshoot, first list all installed plugins that pytest
finds using pytest -VV
:
$ pytest -VV
This is pytest version 6.2.5, imported from /private/tmp/so/lib/python3.9/site-packages/pytest/__init__.py
setuptools registered plugins:
pytest-django-4.5.2 at /private/tmp/so/lib/python3.9/site-packages/pytest_django/plugin.py
pytest-cov-3.0.0 at /private/tmp/so/lib/python3.9/site-packages/pytest_cov/plugin.py
Here, pytest
reports that two plugins are found: pytest-cov
and pytest-django
.
Now, if pytest-django
is not listed, check where it was installed by e.g. issuing pip show pytest-django
and looking for the path under Location
:
$ pip show pytest-django
...
Location: /private/tmp/so/lib/python3.9/site-packages
Or, if pip
is not available for you, check where Python import pytest_django
package from via
$ python -c 'import pytest_django; print(pytest_django.__path__[0])'
/private/tmp/so/lib/python3.9/site-packages/pytest_django
The paths to site-packages
directory in both outputs should match. In this example, both pytest -VV
and pip show pytest-django
report /private/tmp/so/lib/python3.9/site-packages
as the installation path. If those differ, reinstall pytest-django
using the correct Python environment.
- What is the main difference between clean and full_clean function in Django?
- Django request.user.is_authenticated is always true?
- Django form dropdown list of stored models
- How to filter filter_horizontal in Django admin?
- Sending a message to a single user using django-channels
0π
You should correct your pytest.ini
file by removing spaces around =
:
[pytest]
DJANGO_SETTINGS_MODULE=your_project_name.settings
Note:
per Django structure, your project should have a subfolder with settings.py
file in it. You need to point pytest to this file and use dot .
instead of /
.
- How to get the submitted value of a form in a Django class-based view?
- How can I use `email` in "django-rest-framework-simplejwt" instead of `username` to generate token?
- Django β remove trailing zeroes for a Decimal in a template
- Why is Django's Meta an old-style class?
0π
Well, In my case I was having an entry py.test --ignore=outofscope
in my pytest.ini
file, which was causing that warning.
I solved my problem by updating my pytest.ini
file.
- look for any warning/error raised by your editor
- remove any extra space when assigning some values
0π
In my case, for some reason pytest
was not runnin from the currently activated venv
- What is the best IDE setup for web development?
- RuntimeError: __class__ not set defining 'AbstractBaseUser' as <class 'django.contrib.auth.base_user.Abstract BaseUser'>. Was __classcell__ propagated
- How do I get the django HttpRequest from a django rest framework Request?
- Django: IntegrityError during Many To Many add()