How to deactivate django plugin for some tests?
Asked Answered
B

2

8

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?

Barkley answered 23/11, 2012 at 15:18 Comment(0)
G
8

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.

Gerhan answered 23/11, 2012 at 21:16 Comment(2)
I've actually tried it before... just now noticed that I was trying no:dajngo instead of no:django. Thanks Holger.Barkley
ended up using: plgns = [tests.myplugin] pytest.main(sys.argv[1:] + ['-p','no:django'], plugins=plgns)Barkley
F
0

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.

Fellers answered 23/11, 2012 at 21:22 Comment(2)
Oh, just saw Holger's reply. It appears step 2 is not happening in that case.Fellers
Thank you for your answer. I did try using virtualenv with django at first, as you suggest, but ran into problems installing MySQLdb. I'm using windows and I kept failing to create MSI out of source. So I just installed it from binary.Barkley

© 2022 - 2024 — McMap. All rights reserved.