Pytest-django: py.test: error: unrecognized arguments: --reuse-db

Created on 14 Aug 2015  路  4Comments  路  Source: pytest-dev/pytest-django

When I type : py.test show the error

py.test: error: unrecognized arguments: --reuse-db

my pytest.ini

  [pytest]
  addopts = --reuse-db
  DJANGO_SETTINGS_MODULE=untitled1.settings

My test_unidade.py

import pytest

__author__ = 'Rodrigo'
pytestmark = pytest.mark.django_db

@pytest.mark.django_db
def test_cadastra_unidade():
    unidade = TipoUnidade()
    unidade.nome = 'AA'
    unidade.save()

I followed this tutorial http://pytest-django.readthedocs.org/en/latest/database.html

I'd like pytest creates the database like django test

What's wrong?

Most helpful comment

I don't see pytest-django installed in your environment. So, probably, it is a reason. To list active plugins for py.test you can run:

> py.test --traceconfig
========================================================================================== test session starts ===========================================================================================
platform darwin -- Python 2.7.10 -- py-1.4.22 -- pytest-2.6.0
using: pytest-2.6.0 pylib-1.4.22
setuptools registered plugins:
  pytest-django-2.8.0 at /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pytest_django/plugin.pyc
active plugins:
    helpconfig          : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/helpconfig.pyc
    pytestconfig        : <_pytest.config.Config object at 0x101b27b90>
    runner              : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/runner.pyc
    unittest            : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/unittest.pyc
    pastebin            : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/pastebin.pyc
    skipping            : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/skipping.pyc
    genscript           : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/genscript.pyc
    session             : <Session 'repos'>
    tmpdir              : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/tmpdir.pyc
    capture             : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/capture.pyc
    terminalreporter    : <_pytest.terminal.TerminalReporter instance at 0x101d0e758>
    4300360400          : <_pytest.config.PytestPluginManager object at 0x100524ad0>
    assertion           : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/assertion/__init__.pyc
    mark                : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/mark.pyc
    terminal            : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/terminal.pyc
    main                : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/main.pyc
    nose                : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/nose.pyc
    python              : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/python.pyc
    recwarn             : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/recwarn.pyc
    funcmanage          : <_pytest.python.FixtureManager instance at 0x101f1e7e8>
    monkeypatch         : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/monkeypatch.pyc
    resultlog           : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/resultlog.pyc
    capturemanager      : <_pytest.capture.CaptureManager instance at 0x101d7e950>
    django              : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pytest_django/plugin.pyc
    junitxml            : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/junitxml.pyc
    doctest             : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/doctest.pyc
    pdb                 : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/pdb.pyc
plugins: django

When plugin is installed, you can use extra comandline options provided by that plugin, if not, you'll get error.

All 4 comments

Probably it can be related with your environment. Can you show how you run tests? and pip freeze also will be good.

When I remove the param addopts = --reuse-db from pytest.ini the tests runs normally, but the database is not created.

When I run py.test shows only the message

 usage: py.test [options] [file_or_dir] [file_or_dir] [...]
 py.test: error: unrecognized arguments: --reuse-db

requeriments.txt

colorama==0.3.3
Django==1.8.3
django-fab-deploy==0.7.5
django-rest-swagger==0.3.3
djangorestframework==3.2.1
ecdsa==0.13
Jinja2==2.8
Markdown==2.1.0
MarkupSafe==0.23
mirakuru==0.5.0
mysql-connector-python==2.1.2
mysqlclient==1.3.6
path.py==7.6
port-for==0.3.1
py==1.4.30
pyaml==15.6.3
pymlconf==0.3.17
pytest==2.7.1
pytest-dbfixtures==0.12.0
pytest-marks==0.4
PyYAML==3.11
virtualenv==13.1.0

Python 3.4
Windows 7

I don't see pytest-django installed in your environment. So, probably, it is a reason. To list active plugins for py.test you can run:

> py.test --traceconfig
========================================================================================== test session starts ===========================================================================================
platform darwin -- Python 2.7.10 -- py-1.4.22 -- pytest-2.6.0
using: pytest-2.6.0 pylib-1.4.22
setuptools registered plugins:
  pytest-django-2.8.0 at /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pytest_django/plugin.pyc
active plugins:
    helpconfig          : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/helpconfig.pyc
    pytestconfig        : <_pytest.config.Config object at 0x101b27b90>
    runner              : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/runner.pyc
    unittest            : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/unittest.pyc
    pastebin            : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/pastebin.pyc
    skipping            : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/skipping.pyc
    genscript           : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/genscript.pyc
    session             : <Session 'repos'>
    tmpdir              : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/tmpdir.pyc
    capture             : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/capture.pyc
    terminalreporter    : <_pytest.terminal.TerminalReporter instance at 0x101d0e758>
    4300360400          : <_pytest.config.PytestPluginManager object at 0x100524ad0>
    assertion           : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/assertion/__init__.pyc
    mark                : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/mark.pyc
    terminal            : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/terminal.pyc
    main                : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/main.pyc
    nose                : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/nose.pyc
    python              : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/python.pyc
    recwarn             : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/recwarn.pyc
    funcmanage          : <_pytest.python.FixtureManager instance at 0x101f1e7e8>
    monkeypatch         : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/monkeypatch.pyc
    resultlog           : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/resultlog.pyc
    capturemanager      : <_pytest.capture.CaptureManager instance at 0x101d7e950>
    django              : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pytest_django/plugin.pyc
    junitxml            : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/junitxml.pyc
    doctest             : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/doctest.pyc
    pdb                 : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_pytest/pdb.pyc
plugins: django

When plugin is installed, you can use extra comandline options provided by that plugin, if not, you'll get error.

Thanks for the report! As @Stranger6667 points out, this looks like pytest-django is not properly installed.

Please reopen this issue if django shows up in --traceconfig and --reuse-db does still does not work, or if there is anything that you think we can improve in the getting started tutorial.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

blueyed picture blueyed  路  7Comments

ojake picture ojake  路  6Comments

aljosa picture aljosa  路  8Comments

clintonb picture clintonb  路  4Comments

asfaltboy picture asfaltboy  路  5Comments