Skip to content

Commit 6b7c444

Browse files
TheUltraCodeNathan Parsons
authored and
Nathan Parsons
committed
Update "TESTS.md" to show that there is a version of "pytest" for both Python2 and Python3 (#506)
* Update TESTS.md Provides information on the different types of "pytest" available, as well as switched "py.test" to "pytest", as recommended here (pytest-dev/pytest#1629 (comment)). * Fixed a typo. * Small edit. * Update TESTS.md Cleaned it up, addressed what user "N-Parsons" commented on, fixed some errors, and added new information. * Small Change to "PDB" Section.
1 parent b3ba31d commit 6b7c444

File tree

1 file changed

+36
-12
lines changed

1 file changed

+36
-12
lines changed

docs/TESTS.md

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,38 @@ We recommend you install [pytest](http://pytest.org/latest/) and
44
[pytest-cache](http://pythonhosted.org/pytest-cache/). `pytest` is a testing
55
tool that will give you more flexibility over running your unit tests.
66

7+
If you want to install `pytest` for Python 2, then use `pip`.
8+
79
```bash
810
pip install pytest pytest-cache
911
```
12+
If you instead want the version of `pytest` for Python 3, then use `pip3`.
13+
14+
```bash
15+
pip3 install pytest pytest-cache
16+
```
1017

1118
If you get a `command not found` response from your system, you can find a
1219
tutorial on how to install `pip`
1320
[here](https://pip.pypa.io/en/stable/installing/).
1421

22+
**Note:** Whichever version of `pytest` you install last will be the default one used whenever `pytest` is executed, regardless of whether you have installed both versions.
23+
24+
If you want to check what the default version of `pytest` being used is, run the following:
25+
26+
```bash
27+
pytest --version
28+
```
29+
30+
If you have either version of `pytest` installed and you want to specifically run one of the versions, you can run that version by using `python` with the `-m` flag.
31+
32+
For example, you could run the Python 3 version of pytest like so:
33+
34+
```bash
35+
$ python3 -m pytest --version
36+
This is pytest version 3.2.3, imported from /usr/local/lib/python3.5/dist-packages/pytest.py
37+
```
38+
1539
If you choose not to install `pytest`, you can still run tests individually and
1640
skip the rest of this tutorial:
1741

@@ -29,7 +53,7 @@ an example here), place yourself in the directory where that exercise has been
2953
fetched and run:
3054

3155
```bash
32-
py.test bob_test.py
56+
pytest bob_test.py
3357
```
3458

3559
**Note:** To run the tests you need to pass the name of the testsuite file to
@@ -56,22 +80,22 @@ The above will run all the tests, whether they fail or not. If you'd rather stop
5680
the process and exit on the first failure, run:
5781

5882
```bash
59-
py.test -x bob_test.py
83+
pytest -x bob_test.py
6084
```
6185

6286
### Failed Tests First
6387

6488
`pytest-cache` remembers which tests failed, and can run those tests first.
6589

6690
```bash
67-
py.test --ff bob_test.py
91+
pytest --ff bob_test.py
6892
```
6993

7094
### Running All Tests for All Exercises
7195

7296
```bash
7397
cd exercism/python/
74-
py.test
98+
pytest
7599
```
76100

77101
## Recommended Workflow
@@ -80,7 +104,7 @@ We recommend you run this command while working on exercises.
80104

81105
```bash
82106
cd exercism/python/bob
83-
py.test -x --ff bob_test.py
107+
pytest -x --ff bob_test.py
84108
```
85109

86110
## PDB
@@ -89,28 +113,28 @@ Will drop you into the python debugger when a test fails. To learn how to use
89113
pdb, check out the
90114
[documentation](https://docs.python.org/3/library/pdb.html#debugger-commands).
91115

92-
You may also be interested in watching [Clayton Parker's "So you think you can
93-
pdb?" PyCon 2015 talk](https://www.youtube.com/watch?v=P0pIW5tJrRM)
94-
95116
```bash
96-
py.test --pdb bob_test.py
117+
pytest --pdb bob_test.py
97118
```
98119

120+
You may also be interested in watching [Clayton Parker's "So you think you can
121+
pdb?" PyCon 2015 talk](https://www.youtube.com/watch?v=P0pIW5tJrRM).
122+
99123
## PEP8
100124

101125
PEP8 is the [Style Guide for Python
102126
Code](https://www.python.org/dev/peps/pep-0008/). If you would like to test for
103127
compliance to the style guide, install
104-
[pytest-pep8](https://pypi.python.org/pypi/pytest-pep8)
128+
[pytest-pep8](https://pypi.python.org/pypi/pytest-pep8).
105129

106130
```bash
107131
pip install pytest-pep8
108132
```
109133

110-
and add the pep8 flag to your command
134+
Then, just add the `--pep8` flag to your command
111135

112136
```bash
113-
py.test --pep8 bob_test.py
137+
pytest --pep8 bob_test.py
114138
```
115139

116140
Read the [pytest documentation](http://pytest.org/latest/contents.html#toc) and

0 commit comments

Comments
 (0)