| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b3ba31d commit 6b7c444
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,14 +4,38 @@ We recommend you install [pytest](http://pytest.org/latest/) and | |||
| 4 | 4 | [pytest-cache](http://pythonhosted.org/pytest-cache/). `pytest` is a testing | |
| 5 | 5 | tool that will give you more flexibility over running your unit tests. | |
| 6 | 6 | ||
| 7 | + If you want to install `pytest` for Python 2, then use `pip`. | ||
| 8 | + | ||
| 7 | 9 | ```bash | |
| 8 | 10 | pip install pytest pytest-cache | |
| 9 | 11 | ``` | |
| 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 | + ``` | ||
| 10 | 17 | ||
| 11 | 18 | If you get a `command not found` response from your system, you can find a | |
| 12 | 19 | tutorial on how to install `pip` | |
| 13 | 20 | [here](https://pip.pypa.io/en/stable/installing/). | |
| 14 | 21 | ||
| 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 | + | ||
| 15 | 39 | If you choose not to install `pytest`, you can still run tests individually and | |
| 16 | 40 | skip the rest of this tutorial: | |
| 17 | 41 | ||
@@ -29,7 +53,7 @@ an example here), place yourself in the directory where that exercise has been | |||
| 29 | 53 | fetched and run: | |
| 30 | 54 | ||
| 31 | 55 | ```bash | |
| 32 | - py.test bob_test.py | ||
| 56 | + pytest bob_test.py | ||
| 33 | 57 | ``` | |
| 34 | 58 | ||
| 35 | 59 | **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 | |||
| 56 | 80 | the process and exit on the first failure, run: | |
| 57 | 81 | ||
| 58 | 82 | ```bash | |
| 59 | - py.test -x bob_test.py | ||
| 83 | + pytest -x bob_test.py | ||
| 60 | 84 | ``` | |
| 61 | 85 | ||
| 62 | 86 | ### Failed Tests First | |
| 63 | 87 | ||
| 64 | 88 | `pytest-cache` remembers which tests failed, and can run those tests first. | |
| 65 | 89 | ||
| 66 | 90 | ```bash | |
| 67 | - py.test --ff bob_test.py | ||
| 91 | + pytest --ff bob_test.py | ||
| 68 | 92 | ``` | |
| 69 | 93 | ||
| 70 | 94 | ### Running All Tests for All Exercises | |
| 71 | 95 | ||
| 72 | 96 | ```bash | |
| 73 | 97 | cd exercism/python/ | |
| 74 | - py.test | ||
| 98 | + pytest | ||
| 75 | 99 | ``` | |
| 76 | 100 | ||
| 77 | 101 | ## Recommended Workflow | |
@@ -80,7 +104,7 @@ We recommend you run this command while working on exercises. | |||
| 80 | 104 | ||
| 81 | 105 | ```bash | |
| 82 | 106 | cd exercism/python/bob | |
| 83 | - py.test -x --ff bob_test.py | ||
| 107 | + pytest -x --ff bob_test.py | ||
| 84 | 108 | ``` | |
| 85 | 109 | ||
| 86 | 110 | ## PDB | |
@@ -89,28 +113,28 @@ Will drop you into the python debugger when a test fails. To learn how to use | |||
| 89 | 113 | pdb, check out the | |
| 90 | 114 | [documentation](https://docs.python.org/3/library/pdb.html#debugger-commands). | |
| 91 | 115 | ||
| 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 | - | ||
| 95 | 116 | ```bash | |
| 96 | - py.test --pdb bob_test.py | ||
| 117 | + pytest --pdb bob_test.py | ||
| 97 | 118 | ``` | |
| 98 | 119 | ||
| 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 | + | ||
| 99 | 123 | ## PEP8 | |
| 100 | 124 | ||
| 101 | 125 | PEP8 is the [Style Guide for Python | |
| 102 | 126 | Code](https://www.python.org/dev/peps/pep-0008/). If you would like to test for | |
| 103 | 127 | 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). | ||
| 105 | 129 | ||
| 106 | 130 | ```bash | |
| 107 | 131 | pip install pytest-pep8 | |
| 108 | 132 | ``` | |
| 109 | 133 | ||
| 110 | - and add the pep8 flag to your command | ||
| 134 | + Then, just add the `--pep8` flag to your command | ||
| 111 | 135 | ||
| 112 | 136 | ```bash | |
| 113 | - py.test --pep8 bob_test.py | ||
| 137 | + pytest --pep8 bob_test.py | ||
| 114 | 138 | ``` | |
| 115 | 139 | ||
| 116 | 140 | Read the [pytest documentation](http://pytest.org/latest/contents.html#toc) and | |
| Back | FazBrowse Home | New Git URL |
0 commit comments