Issue #4481
closedpulplift does not let you run unit tests with py.test
Description
I think it's typical to go into an area of the tests (functional or unit) and run your test runner of choice, e.g. py.test
. So for example to run these tests I would:
1. activate the pulp3 virtualenv with pulplift using workon pulp
2. cd to pulpcore/tests/unit
3. Run with py.test
I get a whole bunch of errors saying Model class pulpcore.app.models.content.Artifact doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
Note that running the py.test on the functional tests works, so this is a unit test issue.
Workaround¶
You can use manage.py
instead to workaround it. I'm hoping we can get py.test working again somehow also.
Updated by bmbouter almost 6 years ago
- Tags Dev Environment added
- Tags deleted (
Pulp 3 installer)
Updated by bmbouter almost 6 years ago
- Subject changed from pulplift does not let you run tests with py.test to pulplift does not let you run unit tests with py.test
- Description updated (diff)
Updated by CodeHeeler almost 6 years ago
So I did some digging on this and it seems this error may be related to our use of init.py files and the way unittest handles them:
https://code.djangoproject.com/ticket/22280#comment:20
There were several suggested solutions here:
https://medium.com/@michal.bock/fix-weird-exceptions-when-running-django-tests-f58def71b59a
I tried the one involving nose, which I've used in the past, rather than the code change options but still couldn't get rid of the errors.
I wanted to bounce this off folks before going further as we've had the init files a while and I'm not sure how it is broken for you specifically in pulplift only if that's the problem. Does py.test work for you in our old devel way of running vagrant? For that matter, has py.test ever worked for you in our pulplift (want to eliminate the possibility that a recent change caused this)? Thanks!
Updated by dalley almost 6 years ago
I would say this is expected and not an issue. Django unit tests need a bunch of stuff built up, such as the DB connections, the settings file being parsed, a fresh throwaway test-only database, etc. and py.test doesn't know how to do all of that.
There's extensions that I think will do that, but I haven't really tried. But that's why we've just used the Django unit test runner "./manage.py test <app or directory>.
https://pytest-django.readthedocs.io/en/latest/
Since the smash tests are run with Pulp running normally in production, they're more independent in this respect, so you've always been able to just use py.test. But not so for unit tests.
Updated by bmbouter almost 6 years ago
dalley, thank you for explaining this to me. This makes perfect sense. Do you happen to know if we have this documented anywhere? If not I can rewrite this to be a docs story. If so, then we can close NOTABUG. Thanks!
Updated by bmbouter almost 6 years ago
- Status changed from NEW to CLOSED - NOTABUG
Actually I see docs here: https://docs.pulpproject.org/en/3.0/nightly/contributing/dev-setup/runtests.html#running-tests
They probably could use some touching up, but they aren't wrong or missing so I'm closing this as NOTABUG.