Skip to content

Commit 67ac3e3

Browse files
committed
add pytest vs python -m pytest
1 parent 25b39d6 commit 67ac3e3

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

docs/posts/2021/2021-06-12-python-unittest-cheat-sheet.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ Python unittest and Pytest is a big deal, this post just gives some small & quic
1717

1818
<!-- more -->
1919

20+
## pytest vs python -m pytest
21+
22+
`pytest` does not add the current directory to `sys.path[0]` before execution. This means if you have test helper utilities within the `tests` folder, `pytest` may fail to locate them unless an `__init__.py` file exists in the helper directory.
23+
24+
In contrast, `python -m pytest` implicitly adds the current directory to `sys.path[0]`, allowing it to discover test helper utilities even when the helper folder lacks an `__init__.py` file. For this reason, using `python -m pytest` is generally recommended.
25+
2026
## check if is in pytest mode
2127

2228
```python

0 commit comments

Comments
 (0)