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
We use [pytest][pytest: Getting Started Guide] as our website test runner.
4
-
You will need to install `pytest` on your development machine if you want to download and run exercise tests for the Python track locally.
5
+
You will need to install `pytest` on your development machine if you want to run tests for the Python track locally.
5
6
You should also install the following `pytest` plugins:
6
7
7
8
-[pytest-cache][pytest-cache]
8
9
-[pytest-subtests][pytest-subtests]
9
10
10
-
We also recommend using the code linting program [pylint][pylint], as it is part of our automated feedback on the website and can be a very useful static code analysis tool.
11
-
For ease-of-use, the [pytest-pylint][pytest-pylint] plugin for `pytest` will allow you to run `pylint` via `pytest` on the command line.
12
-
13
-
Pylint configuration can be a bit much, so this [tutorial][tutorial from pycqa.org] from pycqa.org can be helpful for getting started, as can this overview of [Code Quality: Tools and Best Practices][Code Quality: Tools and Best Practices] from Real Python.
14
-
15
-
16
-
## Installing pytest
17
-
18
-
Pytest can be installed and updated using the built-in Python utility [`pip`][pip].
19
-
20
-
For additional tips, Brett Cannon has a nice [quick-and-dirty guide on how to install packages for python][brett cannon: quick-and-dirty], along with a great explanation on [why you should use `python -m pip`][brett cannon: python-m-pip].
21
-
For more on Python's command line arguments, see [command line and environment][python command line arguments] in the Python documentation.
11
+
Extended information can be found in our website [Python testing guide][Python track tests page].
22
12
23
-
**Note:**`Python3` may or may not be an alias for Python on your system.
24
-
Please adjust the install commands below accordingly.
25
-
To install `pytest` in a virtual environment, ensure the environment **is activated** prior to executing commands.
26
-
Otherwise, the pytest installation will be global.
To run the included tests, navigate to the folder where the exercise is stored using `cd` in your terminal (_replace `{exercise-folder-location}` below with your path_).
17
+
Test files usually end in `_test.py`, and are the same tests that run on the website when a solution is uploaded.
PS C:\Users\foobar> cd {path\to\exercise-folder-location}
50
27
```
51
28
52
-
## Running the tests
29
+
<br>
53
30
54
-
To run the tests, go to the folder where the exercise is stored using `cd`in your terminal (_replace`{exercise-folder-location}`below with your path_).
31
+
Next, run the `pytest` command in your terminal, replacing`{exercise_test.py}` with the name of the test file:
==================== 7 passed in 0.08s ====================
67
43
```
68
44
69
-
### Common pytest options
70
45
71
-
-`-o` : override default `ini` (_you can use this to avoid marker warnings_)
46
+
### Common options
47
+
-`-o` : override default `pytest.ini` (_you can use this to avoid marker warnings_)
72
48
-`-v` : enable verbose output.
73
49
-`-x` : stop running tests on first failure.
74
50
-`--ff` : run failures from previous test before running other test cases.
75
51
76
-
For other options, see`python3 -m pytest -h`.
52
+
For additional options, use`python3 -m pytest -h` or `py -m pytest -h`.
77
53
78
54
79
55
### Fixing warnings
80
56
81
-
If you do not use the `pytest -o markers=task`in the command above, is possible that you will get `warnings` about "unknown markers" when running a test that uses our _new_ syntax.
57
+
If you do not use `pytest -o markers=task`when invoking `pytest`, you might receive a `PytestUnknownMarkWarning` for tests that use our new syntax:
82
58
83
-
To avoid typing `pytest -o markers=task` for every test you run, you can use a `pytest.ini` configuration file, which can be downloaded from the top level of the Python track directory: [pytest.ini][pytest.ini].
59
+
```bash
60
+
PytestUnknownMarkWarning: Unknown pytest.mark.task - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/mark.html
61
+
```
62
+
63
+
To avoid typing `pytest -o markers=task` for every test you run, you can use a `pytest.ini` configuration file.
64
+
We have made one that can be downloaded from the top level of the Python track directory: [pytest.ini][pytest.ini].
84
65
85
66
You can also create your own `pytest.ini` file with the following content:
86
67
@@ -90,65 +71,23 @@ markers =
90
71
task: A concept exercise task.
91
72
```
92
73
93
-
Placing this file in the _root_ or _working_ directory for the Python track exercises will register the marks and stop the warnings.
74
+
Placing the `pytest.ini`file in the _root_ or _working_ directory for your Python track exercises will register the marks and stop the warnings.
94
75
More information on pytest marks can be found in the `pytest` documentation on [marking test functions][pytest: marking test functions with attributes] and the `pytest` documentation on [working with custom markers][pytest: working with custom markers].
95
76
96
-
_More information on customizing pytest configurations can be found in the pytest documentation on [configuration file formats][pytest: configuration file formats]_
97
-
98
-
99
-
### Recommended Workflow
100
-
101
-
We recommend using the following commands to make your debugging easier and (possibly) faster:
102
-
103
-
First change your working directory to the directory of the exercise you want to test:
104
-
105
-
```bash
106
-
$(my_venv)cd path/to/exercise
107
-
```
108
-
109
-
Then, run the tests together with the previously explained arguments `-x` and`--ff`:
Information on customizing pytest configurations can be found in the `pytest` documentation on [configuration file formats][pytest: configuration file formats].
128
78
129
-
Dropping into `PDB` will allow you to step through your code viewing the current scope, as well as checking the value of variables and the signature of different functions.
130
-
More details on the `PDB` module can be found in the [Python documentation on PDB][pdb].
131
-
Additionally, the [pytest docs on PDB][pytest-pdb] and [this guide from Real Python](https://realpython.com/python-debugging-pdb/) are extremely helpful.
132
79
133
-
## Extending your IDE
80
+
###Extending your IDE or Code Editor
134
81
135
-
If you'd like to extend your IDE with some tools that will help you with testing and improving your code, the Python track [tools page][Python track tools page] on exercism.org goes over some options.
82
+
Many IDEs and code editors have built-in support for using `pytest` and other code quality tools.
83
+
Some community-sourced options can be found on our [Python track tools page][Python track tools page].
136
84
137
-
[Code Quality: Tools and Best Practices]: https://realpython.com/python-code-quality/
138
85
[Pytest: Getting Started Guide]: https://docs.pytest.org/en/latest/getting-started.html
0 commit comments