pytest-dev / pytest-dev/pytest-django
Tests using `live_server` flush all data of my database
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 367
- PR merge metrics
- No merged PRs in 30d
Description
In order to access existing database, I put these code into conftest.py according to https://pytest-django.readthedocs.io/en/latest/database.html?highlight=rollback#using-an-existing-external-database-for-tests
@pytest.fixture(scope='session')
def django_db_setup():
settings.DATABASES['default'] = {
'ENGINE': 'django.db.backends.mysql',
'HOST': 'db.example.com',
'NAME': 'external_db',
}
After running test functions like this one, all data of the database were flushed.
def test_xxx(live_server):
r = requests.get(live_server + reverse("xxx"))
# some assertions
Is there anyway to use live_server fixture without modifying the existing database?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read the database setup guidance linked in the issue, then inspect conftest.py’s django_db_setup and the live_server fixture usage. Reproduce the test against the external MySQL database and verify that using live_server no longer flushes existing data.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, mysql, python
- Domain
- database, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100