Project

Profile

Help

Issue #4481

pulplift does not let you run unit tests with py.test

Added by bmbouter 8 months ago. Updated 6 months ago.

Status:
CLOSED - NOTABUG
Priority:
Normal
Assignee:
-
Category:
-
Sprint/Milestone:
Start date:
Due date:
Severity:
2. Medium
Version:
Platform Release:
Blocks Release:
OS:
Backwards Incompatible:
No
Triaged:
No
Groomed:
No
Sprint Candidate:
No
Tags:
Dev Environment
QA Contact:
Complexity:
Smash Test:
Verified:
No
Verification Required:
No
Sprint:

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.

History

#1 Updated by bmbouter 8 months ago

  • Tags Dev Environment added
  • Tags deleted (Pulp 3 installer)

#2 Updated by bmbouter 8 months ago

  • Description updated (diff)

#3 Updated by bmbouter 8 months 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)

#4 Updated by CodeHeeler 8 months 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!

#5 Updated by dalley 8 months 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.

#6 Updated by bmbouter 8 months 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!

#7 Updated by bmbouter 8 months 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.

#8 Updated by daviddavis 6 months ago

  • Sprint/Milestone set to 3.0

#9 Updated by bmbouter 6 months ago

  • Tags deleted (Pulp 3)

Please register to edit this issue

Also available in: Atom PDF