pytest not run
See original GitHub issueI launched a project. After creating the model, I’m trying to run tests. But I get an error.
ERROR collecting server/apps/main/admin.py
server/apps/main/admin.py:12: in <module>
admin.site.register(File, Dd)
.venv/lib/python3.7/site-packages/django/contrib/admin/sites.py:110: in register
raise AlreadyRegistered('The model %s is already registered' % model.__name__)
E django.contrib.admin.sites.AlreadyRegistered: The model File is already registered
ERROR collecting server/apps/main/models.py
server/apps/main/models.py:28: in <module>
class File(AbstractDefaultModel):
.venv/lib/python3.7/site-packages/django/db/models/base.py:118: in __new__
"INSTALLED_APPS." % (module, name)
E RuntimeError: Model class main.models.File doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
my code models.py
class AbstractDefaultModel(models.Model):
is_active = models.BooleanField(
verbose_name=_('is_active'),
default=True)
created_at = models.DateTimeField(
verbose_name=_('created at'),
auto_now_add=True)
updated_at = models.DateTimeField(
verbose_name=_('updated at'),
auto_now=True)
def __str__(self):
return '{id}'.format(id=self.id)
class Meta:
abstract = True
class File(AbstractDefaultModel):
code = models.PositiveIntegerField(
verbose_name='code',
unique=True,
editable=True)
profile = models.CharField(
verbose_name='name',
max_length=100,
blank=True,
null=True)
class Meta:
verbose_name = 'file'
verbose_name_plural = 'files'
my code admin.py
from server.apps.main.models import File
class FileAdmin(admin.ModelAdmin):
list_display = ['id', 'profile']
admin.site.register(File, FileAdmin)
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (9 by maintainers)
Top Results From Across the Web
pytest doesn't run any test - Stack Overflow
pytest doesn't run any tests and it is not clear why. I tried to use --debug but didn't get any valuable information. It...
Read more >How to invoke pytest — pytest documentation
In general, pytest is invoked with the command pytest (see below for other ways to invoke pytest). This will execute all tests in...
Read more >Running Tests with pytest - The Carpentries Incubator
With pytest, this is the command-line tool called pytest . When pytest is run, it will search all directories below where it was...
Read more >py.test not running all test by selected marks #4340 - GitHub
My problem is that py.test ignoring few tests that having marks (@pytest.mark.some_mark). I have a folder named featureapp that contain 2 ...
Read more >Pytest - Quick Guide - Tutorialspoint
Pytest - Run Tests in Parallel. By default, pytest runs tests in sequential order. In a real scenario, a test suite will have...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The problem with test, because pydoc builds module path from package (folder with init.py). For example: you have server/apps/main/models Pydoc scans and look into parent folder - models. If init.py exists, it add to path models. Then pydoc go up to top folder - main, which have _init.py. Now current path - main.models, but apps folder - without init. Django builds modules path differently. As result main.models (from pydoc) != server.apps.main.models (from django)
Solution: add init.py into apps dir
@vaad2 thanks! Do you want to send a PR with the fix?