-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move models to respective test modules #2161
Conversation
|
Want to merge this as it currently stands or wait for the other bits too? |
I will probably push in the other bits too first, plus try to think of approaches on how to solve this with as little repetition as possible. |
What annoys me the most with having the models outside the models.py file is that I have absolutely no idea of the side effects it could bring, in particular regarding the Django auto discovery. |
We can try to sit on 2 chairs at once, and have models very basic and stale in |
Na, if the tests pass it's fine. I just need to go through the Django code to understand about this. |
Wasn't aware there's any difference with them being in test modules or models.py? |
Turned out to be useless with As far as I know the difference is that if the models are in |
It gets it from the python package (for < 1.7). If you put your models in a models directory, they'll be linked to the application named "models" unless you give them an app_label.
Django auto discovery expects them to be in the models file. |
Defining models only for tests in their test modules is standard usage surely tho. It's always what we used to do with rest framework originally, only more recently that models.py got created. Certainly nothing to do with py.test. |
Update: Stupidly moving models to respective test modules doesn't really work out because in Django 1.7 all models go through register_model which checks if it's been registered or not, and if it has, if it's the same model belonging to the same module, first of all, for some reason this checks fails under pytest, and secondly it would still give a warning, so not all that great. Yes, of course, you can just rename the model, but that would imply names like The only more or less valid idea I have is specifying a custom In any case, this one should be merged, as it's a completely different story now. |
Grand, thanks @maryokhin |
Move models to respective test modules
I'm not sure what this issue status is now. |
Think there's a few minor bits of clean up there that could still be addressed. |
What needs to be sorted out:
app_label
, maybe remove it completely and set app label specifically on each model them from a common constantTESTS_APP_LABEL='tests'
somewhere in settings i.e.conftest.py
orutils.py
.P. S. As a side question. why don't asserts in tests set
response.data
as the message arg i.e. toassertEqual()
so that when it fails the developer can see the error message, not just the assertion failure message?