Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django pytest not working as expected

Tags:

django

pytest

I'm trying to use pytest-django. I think it is correctly installed:

sudo pip install --upgrade pytest-django
Requirement already up-to-date: pytest-django in /usr/local/lib/python2.6/dist-packages

However:

py.test --ds myproj.settings_module
usage: py.test [options] [file_or_dir] [file_or_dir] [...]
py.test: error: unrecognized arguments: --ds

what's the problem? How can I check that django-pytest is installed?

more info

$ which py.test
/usr/local/bin/py.test
$ py.test --version
This is pytest version 2.5.2, imported from /usr/local/lib/python2.6/dist-packages/pytest.pyc

more info (2)

$ which python
/usr/bin/python
$ python
Python 2.7.3 (default, Jan  2 2013, 16:53:07) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pytest_django
>>> 
$ py.test --traceconfig
PLUGIN registered: <_pytest.python.FixtureManager instance at 0x8fa0d6c>
======================================================================== test session starts =========================================================================
platform linux2 -- Python 2.7.3 -- py-1.4.20 -- pytest-2.5.2
using: pytest-2.5.2 pylib-1.4.20
active plugins:
    helpconfig          : /usr/local/lib/python2.7/dist-packages/_pytest/helpconfig.pyc
    pytestconfig        : <_pytest.config.Config object at 0x8ce0f6c>
    runner              : /usr/local/lib/python2.7/dist-packages/_pytest/runner.pyc
    unittest            : /usr/local/lib/python2.7/dist-packages/_pytest/unittest.pyc
    pastebin            : /usr/local/lib/python2.7/dist-packages/_pytest/pastebin.pyc
    skipping            : /usr/local/lib/python2.7/dist-packages/_pytest/skipping.pyc
    genscript           : /usr/local/lib/python2.7/dist-packages/_pytest/genscript.pyc
    session             : <Session 'delme'>
    tmpdir              : /usr/local/lib/python2.7/dist-packages/_pytest/tmpdir.pyc
    capture             : /usr/local/lib/python2.7/dist-packages/_pytest/capture.pyc
    terminalreporter    : <_pytest.terminal.TerminalReporter instance at 0x8df44cc>
    assertion           : /usr/local/lib/python2.7/dist-packages/_pytest/assertion/__init__.pyc
    mark                : /usr/local/lib/python2.7/dist-packages/_pytest/mark.pyc
    terminal            : /usr/local/lib/python2.7/dist-packages/_pytest/terminal.pyc
    main                : /usr/local/lib/python2.7/dist-packages/_pytest/main.pyc
    nose                : /usr/local/lib/python2.7/dist-packages/_pytest/nose.pyc
    python              : /usr/local/lib/python2.7/dist-packages/_pytest/python.pyc
    146879340           : <_pytest.config.PytestPluginManager object at 0x8c1336c>
    recwarn             : /usr/local/lib/python2.7/dist-packages/_pytest/recwarn.pyc
    funcmanage          : <_pytest.python.FixtureManager instance at 0x8fa0d6c>
    monkeypatch         : /usr/local/lib/python2.7/dist-packages/_pytest/monkeypatch.pyc
    resultlog           : /usr/local/lib/python2.7/dist-packages/_pytest/resultlog.pyc
    capturemanager      : <_pytest.capture.CaptureManager instance at 0x8df972c>
    junitxml            : /usr/local/lib/python2.7/dist-packages/_pytest/junitxml.pyc
    doctest             : /usr/local/lib/python2.7/dist-packages/_pytest/doctest.pyc
    pdb                 : /usr/local/lib/python2.7/dist-packages/_pytest/pdb.pyc
collected 0 items 

==========================================================================  in 0.00 seconds ==========================================================================
like image 798
Emanuele Paolini Avatar asked Dec 19 '25 01:12

Emanuele Paolini


1 Answers

The py.test documentation recommends using py.test --traceconfig to determine what plugins are installed. (Source: http://pytest.org/latest/plugins.html#finding-out-which-plugins-are-active)

As a sanity check, I would make sure you can import pytest_django at a Python prompt.

$ which python
// Expect this to be /usr/local/bin/python
$ python
>>> import pytest_django

At the very least, you are working with two versions of Python between your initial question and your "more information (2)" section. Notice how first the paths begin with /usr/local/lib/python2.6/ and then later they begin with /usr/local/lib/python2.7/? This is pretty weird, and a mismatch like this may explain why you can import pytest_django and yet py.test isn't seeing the plugin installed.

I recommend using virtualenv if at all possible to side-step environment issues like this. Here is a good tutorial about how to get started: http://www.pythonforbeginners.com/basics/how-to-use-python-virtualenv

Try this:

sudo pip install virtualenv
virtualenv env --no-site-packages --python=python2.6  // Can be python2.7 too.
source env/bin/activate
pip install pytest-django  // Should pull in Django and pytest dependencies.
py.test --traceconfig
like image 101
Frank T Avatar answered Dec 20 '25 19:12

Frank T



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!