Alex Okrushko
Alex Okrushko

Reputation: 7372

How to deactivate django plugin for some tests?

I'm running some tests for Django, and some other tests for the website using Selenium.

My choice of Testing framework is amazing Pytest.

for testing Django I've currently installed pytest-django plugin and tests for Django run as expected, however now I'm back to my previous tests that don't need Django plugin.

I start tests and the Django plugin is picked up automatically.
I've checked the documentation and found the article where it is explained how to disable\deactivate plugins, however when I run this command:

py.test -p no:django 

I get an error that my "DJANGO_SETTINGS_MODULE" is not on sys.path.

Also

commands like:

py.test --traceconfig

or

py.test --version

throw me the same error. Looks like Django plugin is getting to deep? Why is it called when I'm just checking the version or the 'installed plugins'?

QUESTION: Is there any way to temporary deactivate this plugin without uninstalling it?

Upvotes: 8

Views: 1932

Answers (2)

flub
flub

Reputation: 6357

IIRC this is because of a combination of things:

  • On startup py.test looks for the setuptool entrypoint "pytest11"
  • Entrypoints get imported before they get activated or deactivated
  • pytest-django (as released, currently 1.4) does a load of Django imports upfront
  • A lot of Django needs the settings module configured even at import time

Unfortunately this is unavoidable in the released version of pytest-django. And the answer originally was: no, run the pytest-django and other tests in different virtualenvs.

However it is also the reason we started work on a version of the plugin which avoids these problems. What I consider the best version right now is the pytest23 branch at https://github.com/flub/pytest_django This version is pretty feature complete, certainly compared to the released version, it just needs a little more polishing mainly on the tests and documentation.

I believe/hope that within the next few weeks this branch will be merged and released, I just need to get Andreas to have a look through and agree. I consider it certainly stable enough to start using.

Upvotes: 0

hpk42
hpk42

Reputation: 23581

This should work. When i install pytest-2.3.4 and run py.test -p no:django --version i don't get the DJANGO_SETTINGS issues. I get it when i leave away the -p no:django disabling. If it doesn't work, please link to a full trace on a pastebin.

Upvotes: 8

Related Questions