django.db.utils.OperationalError: no such table: django_site while running pytest in lms-shell

I have a modified openedx devstack and I am trying to run tests for lms but I am getting this error:

django.db.utils.OperationalError: no such table: django_site

This is the command I am using:

pytest --create-db --ds=lms.envs.test --exitfirst openedx/core/

This is the database dictionary of my lms.envs.test:

    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'edxapp',
        'ATOMIC_REQUESTS': True,
    'student_module_history': {
        'ENGINE': 'django.db.backends.sqlite3',

How can I run these tests without error?

Are the existing tests failing, or new tests that you’ve added? If the latter, you probably need to add @pytest.mark.django_db. If the former, were the tests working before you made the changes?

Yes the existing tests were working fine, there are no new tests added yet. I’ve been making changes for several months now so It’s not obvious what caused the tests to stop executing. I need them back so I can add more of my own.
I do have the django_site table in my database, could it be that pytest is not creating its test database properly?

It could, yes.

Can you try stepping back in your git history until you get to a point where things are working? Or switch back to the master branch temporarily?