Commit Graph

9 Commits

Author SHA1 Message Date
Dani Hodovic
ff0122acd6
Use pytest-django --reuse-db for faster tests
Pytest-django allows you to re-use database setups between tests for
quicker test runs. This is especially useful for large projects with many
migrations.

For example, here's a project of mine with 40+ migrations:

with --reuse-db
```
pytest --reuse-db  2.54s user 0.35s system 108% cpu 2.669 total
```

without --reuse-db
```
pytest 7.40s user 0.34s system 50% cpu 15.240 total
```

Caveat: if your model happens to change you need to manually --create-db
to ensure migrations are applied.

https://pytest-django.readthedocs.io/en/latest/database.html#reuse-db-reuse-the-testing-database-between-test-runs
2019-11-13 23:28:38 +01:00
Dani Hodovic
c6bd37adcc
Add default tests.py file pattern to pytest
`./manage.py startapp` generates a tests.py file by default. This is
ignored by pytest unless specified.
2019-09-04 15:59:31 +02:00
Dani Hodovic
f02aa463a7
Always use test settings in pytest
You can alternatively use DJANGO_SETTINGS_MODULE, but this is overridden
by the environment variable of the same name. In order to always run it
with test settings, regardless of the environment variable use --ds.

https://pytest-django.readthedocs.io/en/latest/configuring_django.html
2019-07-09 08:54:31 +08:00
Nikita P. Shupeyko
3e2bf3f701 Prettify template's pytest.ini 2018-03-09 13:06:45 +03:00
Ivan Savov
8b1fd8ec44 added norecursedirs to pytest.ini (#1376)
This is to ensure running `pytest` in project root works when using Python 3.6 (otherwise tries to run python tests in `node-gyp` node module and fails with:

```
―――――――――――――――――――――――――――――――――――――――――――― ERROR collecting node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py ――――――――――――――――――――――――――――――――――――――――――――
../venv/lib/python3.6/site-packages/_pytest/python.py:395: in _importtestmodule
    mod = self.fspath.pyimport(ensuresyspath=importmode)
../venv/lib/python3.6/site-packages/py/_path/local.py:662: in pyimport
    __import__(modname)
E     File "/Users/ivan/Projects/Minireference/ClassroomLinksProject/classroomlinks/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 37
E       print '%s:%s:%d:%s %s' % (mode.upper(), os.path.basename(ctx[0]),
E                            ^
E   SyntaxError: invalid syntax
```
2017-12-13 15:28:14 +03:00
Shupeyko Nikita
8c5c521b29 Revert "Configure pytest to exit after first num failures or errors (#1292)"
This reverts commit dec3305cd5.
2017-08-29 15:45:17 +03:00
Shupeyko Nikita
dec3305cd5 Configure pytest to exit after first num failures or errors (#1292) 2017-08-23 13:58:10 +04:00
Nikita P. Shupeyko
d0a21a50df Fix pytest DJANGO_SETTINGS_MODULE
Switch from DJANGO_SETTINGS_MODULE = config.settings.local to DJANGO_SETTINGS_MODULE = config.settings.test
2017-02-10 15:10:41 +03:00
Audrey Roy Greenfeld
15f350f05e Change repo_name to project_slug for clarity. 2016-04-20 10:00:35 -07:00