Skip to content

Commit ffa11c6

Browse files
committed
Merge workflow document into testing
Fixes exercism#315
1 parent 37913a2 commit ffa11c6

2 files changed

Lines changed: 95 additions & 97 deletions

File tree

docs/TESTS.md

Lines changed: 95 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,117 @@
11
# Installing `pytest`
22

3-
First of all, install `pytest` through `pip`.
3+
We recommend you install [pytest](http://pytest.org/latest/) and
4+
[pytest-cache](http://pythonhosted.org/pytest-cache/). `pytest` is a testing
5+
tool that will give you more flexibility over running your unit tests.
6+
7+
```bash
8+
pip install
9+
pytest pytest-cache
410
```
5-
pip install pytest
11+
12+
If you get a `command not found` response from your system, you can find a
13+
tutorial on how to install `pip`
14+
[here](https://pip.pypa.io/en/stable/installing/).
15+
16+
If you choose not to install `pytest`, you can still run tests individually and
17+
skip the rest of this tutorial:
18+
19+
```bash
20+
cd exercism/python/bob
21+
python bob_test.py
622
```
7-
If you get a `command not found` response from your system, you can find a tutorial on how to install `pip` [here](https://pip.pypa.io/en/stable/installing/).
823

924
# Running the Tests
1025

11-
To run the tests for a specific exercise (we will take the `bob.py` exercise as an example here), place yourself in the directory where that exercise has been fetched and run:
26+
## Run All Tests
1227

13-
```
28+
To run all tests for a specific exercise (we will take the `bob.py` exercise as
29+
an example here), place yourself in the directory where that exercise has been
30+
fetched and run:
31+
32+
```bash
1433
py.test bob_test.py
1534
```
1635

17-
This will run all the tests, whether they fail or not. If you'd rather stop the process and exit on the first failure, run:
36+
**Note:** To run the tests you need to pass the name of the testsuite file to
37+
`pytest` (generally, the file ending with `_test.py`), **NOT** the file you
38+
created to solve the problem (which is your _implementation_). This is because
39+
in the latter case, since there are no defined test cases in your
40+
implementation, `pytest` will just return a positive result, specifying that
41+
it ran zero tests. Like this:
42+
43+
```
44+
============================= bob.py ==============================
45+
46+
---------------------------------------------------------------------
47+
48+
Ran 0 tests in 0.000s
1849
50+
OK
1951
```
52+
53+
## More `pytest` Examples
54+
55+
### Stop After First Failure
56+
The above will run all the tests, whether they fail or not. If you'd rather stop
57+
the process and exit on the first failure, run:
58+
59+
```bash
2060
py.test -x bob_test.py
2161
```
2262

23-
**Note:** To run the tests you need to pass the name of the testsuite file to `pytest` (generally, the file ending with `_test.py`), **NOT** the file you created to solve the problem (which is your _implementation_). This is because in the latter case, since there are no defined test cases in your implementation, `pytest` will just return a positive result, specifying that it ran zero tests. Like this:
63+
### Failed Tests First
2464

65+
`pytest-cache` remembers which tests failed, and can run those tests first.
66+
67+
```bash
68+
py.test --ff bob_test.py
2569
```
26-
============================= bob.py ==============================
2770

28-
----------------------------------------------------------------------
71+
### Running All Tests for All Exercises
2972

30-
Ran 0 tests in 0.000s
73+
```bash
74+
cd exercism/python/ py.test
75+
```
3176

32-
OK
77+
## Recommended Workflow
78+
79+
We recommend you run this command while working on exercises.
80+
81+
```bash
82+
cd exercism/python/bob py.test -x --ff bob_test.py
83+
```
84+
85+
## PDB
86+
87+
Will drop you into the python debugger when a test fails. To learn how to use
88+
pdb, check out the
89+
[documentation](https://docs.python.org/3/library/pdb.html#debugger-commands).
90+
91+
You may also be interested in watching [Clayton Parker's "So you think you can
92+
pdb?" PyCon 2015 talk](https://www.youtube.com/watch?v=P0pIW5tJrRM)
93+
94+
```bash
95+
py.test --pdb bob_test.py
96+
```
97+
98+
## PEP8
99+
100+
PEP8 is the [Style Guide for Python
101+
Code](https://www.python.org/dev/peps/pep-0008/). If you would like to test for
102+
compliance to the style guide, install
103+
[pytest-pep8](https://pypi.python.org/pypi/pytest-pep8)
104+
105+
```bash
106+
pip install pytest-pep8
33107
```
108+
109+
and add the pep8 flag to your command
110+
111+
```bash
112+
py.test --pep8 bob_test.py
113+
```
114+
115+
Read the [pytest documentation](http://pytest.org/latest/contents.html#toc) and
116+
[pytest-cache](http://pythonhosted.org/pytest-cache/) documentation to learn
117+
more.

docs/WORKFLOW.md

Lines changed: 0 additions & 86 deletions
This file was deleted.

0 commit comments

Comments
 (0)