You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+50Lines changed: 50 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -95,9 +95,59 @@ Just run the project from `example` directory, head to http://127.0.0.1:8000, lo
95
95
- Python 2.7.x: Django 1.7, 1.8, 1.9, 1.10
96
96
- Python 3.x: Django 1.8, 1.9, 1.10
97
97
98
+
# Testing
99
+
100
+
In order to support multiple Django and Python versions we use:
101
+
102
+
- `py.test` - test runner
103
+
- `tox` - handy tool to test app with different versions of Pythons & libraries
104
+
- `selenium`
105
+
- `coverage`
106
+
107
+
Install them via `pip install -r requirements/dev.txt`
108
+
109
+
To test things in specific environment, run the following commands:
110
+
111
+
```bash
112
+
# Clear previous coverage data.
113
+
coverage erase
114
+
115
+
# This command can be ran multiple times.
116
+
tox -e <python_ver>-<django_ver>
117
+
# Possible python_ver values: `py27`, `py36`
118
+
# Possible django_ver values: `17`, `18`, `19`, `110`
119
+
# Values can be comma-seperated, e. g. `-e py27-17,py27-18,py36-18`
120
+
# If you omit `-e ...` parameter, all environments will be tests.
121
+
# Also - not problems with running this within a virtualenv.
122
+
# Check tox.ini for these values.
123
+
124
+
# Run this once all tests passed on all environment.
125
+
coverage combine
126
+
127
+
# Render HTML with coverage info.
128
+
coverage html
129
+
# ...or simply display % of covered SLOC for each file.
130
+
coverage report
131
+
```
132
+
133
+
To add a new Django version for testing, add it into `tox.ini`, lines 3-4.
134
+
135
+
Why do we need `tox` and `coverage combine`? Because different versions of Python & libraries lead to different code execution: for example, consider this code:
136
+
137
+
```python
138
+
import sys
139
+
if sys.version_info.major == 2:
140
+
foo = 'spam'# Not covered in Python 3.x, leads to coverage < 100%
141
+
else:
142
+
foo = 'eggs'# Not covered in Python 2.x, leads to coverage < 100%
143
+
```
144
+
145
+
Using `tox` and `coverage combine` we're able to "merge" coverage info from across different environments.
146
+
98
147
# Known issues
99
148
100
149
- Not tested with empty fields.
150
+
- Tests sometimes fail randomly due to some Selenium timeout issue. Weird.
0 commit comments