Skip to content

Commit 160cf40

Browse files
committed
🎨 format README.md
1 parent 6a4c34e commit 160cf40

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

tests/README.md

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ backgroundColor: #fff
1212
## Quick start
1313

1414
### Installation
15+
1516
Install pytest. e.g., from the "dev" dependencies
17+
1618
```bash
1719
pip install ".[dev]"
1820
```
1921

2022
### How to use
23+
2124
To execute the tests run e.g.
25+
2226
```bash
2327
pytest
2428
```
@@ -30,43 +34,46 @@ pytest
3034
---
3135

3236
### Folder and test naming
37+
3338
1. The tests for functions in `<filename>.py` should go in `tests/test_<filename>.py`
34-
35-
e.g., the tests for [python_package/mockup.py](../src/python_package/mockup.py) are in [tests/test_mockup.py](test_mockup.py)
3639

37-
2. The test names should start with `def test_<corresponding_function_name> ...`
40+
e.g., the tests for [python_package/mockup.py](../src/python_package/mockup.py) are in [tests/test_mockup.py](test_mockup.py)
41+
42+
2. The test names should start with `def test_<corresponding_function_name> ...`
3843

39-
e.g., `def test_hello_world(): ...`
44+
e.g., `def test_hello_world(): ...`
4045

4146
---
4247

4348
### Some Pytest decorators
4449

4550
1. To indicate that the test function is expected to fail you can prepend
46-
```python
47-
@pytest.mark.xfail(raises=TypeError)
48-
def test_hello_world_str(): ...
49-
```
51+
52+
```python
53+
@pytest.mark.xfail(raises=TypeError)
54+
def test_hello_world_str(): ...
55+
```
5056

5157
---
5258

5359
2. To setup and cleanup any resources for a test you can use [pytest fixtures with `yield`](https://dev.to/dawidbeno/understanding-yield-in-pytest-fixtures-4m38)
5460

55-
```python
56-
@pytest.fixture
57-
def temp_file():
58-
# set up
59-
< code to create a file>
60-
# return
61-
yield
62-
the_file
63-
# clean up
64-
< code to remove the file>
65-
```
61+
```python
62+
@pytest.fixture
63+
def temp_file():
64+
# set up
65+
< code to create a file>
66+
# return
67+
yield
68+
the_file
69+
# clean up
70+
< code to remove the file>
71+
```
6672

6773
---
6874

6975
### Doctests
76+
7077
You can also include tests in your docstrings using `>>>` followed by the expected result e.g.
7178

7279
```python
@@ -82,7 +89,8 @@ def hello_world(n):
8289
...
8390
"""
8491
```
85-
*Needs `addopts = --doctest-modules` in pytest.ini
92+
93+
Needs `addopts = --doctest-modules` in `pytest.ini` in root of directory
8694

8795
---
8896

@@ -102,6 +110,3 @@ def saved_world(filename):
102110
...
103111
"""
104112
```
105-
106-
107-

0 commit comments

Comments
 (0)