# python
## pandas
[Link](https://gist.github.com/bitliner/217f4162ad4160cd7c969ea73fdc591c)
## pytest
### mock
Assume `pip install pytest-mock` or `poetry add pytest-mock`
```python
def test_me(mocker):
mocker.patch(
"module1.module2.module3.function", return_value=value
)
```
Be careful with `from module1.module2 import fn` statement, see [link](http://www.gregreda.com/2021/06/28/mocking-imported-module-function-python/)
[pytest-mock documentation](https://pytest-mock.readthedocs.io/en/latest/)
### snapshot testing
```bash
pip install pytest-snapshot
```
```python
def test_me(snapshot):
snapshot.assert_match(output)
```
If pandas dataframe, then use `output.to_csv()` since `assert_match()` accepts strings, not bytes
```bash
pytest --snapshot-update
```
## simple server
`python -m SimpleHTTPServer -d `
## unused dependencies
[Tool to identify unused deps](https://fpgmaas.github.io/deptry/)
## poetry
**add dev deps**
`poetry add --group dev deptry`
**set in-project env** (folder .venv will be within the project)
`poetry config virtualenvs.in-project true`