Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions docs/docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,42 @@ Ran 14 tests in 4.142s
OK
Destroying test database for alias 'default'...
```

Optionally, `pytest` can be used after installing `pytest` and `pytest-django`
(which e.g. allows to execute single test cases):

```bash
$ cd /path/to/jane/root
$ cd src
$ pytest
==================== test session starts ==================================
platform linux -- Python 3.4.4, pytest-3.0.5, py-1.4.31, pluggy-0.4.0
Django settings: jane.settings (from ini file)
rootdir: /home/megies/git/jane-master/src, inifile: pytest.ini
plugins: django-3.1.2
collected 53 items

jane/documents/tests/test_documents.py ...
jane/fdsnws/tests/test_dataselect_1.py ................
jane/fdsnws/tests/test_station_1.py ................
jane/jane/tests/test_code_formatting.py .
jane/quakeml/tests/test_quakeml.py ............
jane/stationxml/tests/test_stationxml.py .
jane/waveforms/tests/test_core.py ...
jane/waveforms/tests/test_management_commands.py .

================= 53 passed in 33.48 seconds ==============================

$ pytest -k test_radial_query_quakeml
==================== test session starts ==================================
platform linux -- Python 3.4.4, pytest-3.0.5, py-1.4.31, pluggy-0.4.0
Django settings: jane.settings (from ini file)
rootdir: /home/megies/git/jane-master/src, inifile: pytest.ini
plugins: django-3.1.2
collected 53 items

jane/quakeml/tests/test_quakeml.py .

==================== 52 tests deselected ==================================
============ 1 passed, 52 deselected in 4.92 seconds ======================
```
4 changes: 3 additions & 1 deletion src/jane/local_settings.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ JANE_FDSN_STATIONXML_SOURCE = "Jane"


# Change the settings for the test database here!
if 'test' in sys.argv:
# for pytest-django, this did not work for me:
# https://stackoverflow.com/a/25188424
if 'test' in sys.argv or "pytest" in sys.modules:
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
Expand Down
4 changes: 3 additions & 1 deletion src/jane/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ def show_toolbar(request):


# speed up tests
if 'test' in sys.argv:
# for pytest-django, this did not work for me:
# https://stackoverflow.com/a/25188424
if 'test' in sys.argv or "pytest" in sys.modules:
print("Using test settings ...")
PASSWORD_HASHERS = (
'django.contrib.auth.hashers.MD5PasswordHasher',
Expand Down
5 changes: 5 additions & 0 deletions src/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[pytest]
DJANGO_SETTINGS_MODULE = jane.settings
django_find_project = true
# -- recommended but optional:
python_files = test_*.py