Skip to content

Instantly share code, notes, and snippets.

@bitliner
Last active May 14, 2023 14:31
Show Gist options
  • Save bitliner/b649a5634ac422856c3acd891f9bcc1a to your computer and use it in GitHub Desktop.
Save bitliner/b649a5634ac422856c3acd891f9bcc1a to your computer and use it in GitHub Desktop.

python

pandas

Link


pytest

mock

Assume pip install pytest-mock or poetry add pytest-mock

def test_me(mocker):
    mocker.patch(
        "module1.module2.module3.function", return_value=value
    )

Be careful with from module1.module2 import fn statement, see link

pytest-mock documentation


snapshot testing

pip install pytest-snapshot
def test_me(snapshot):
    snapshot.assert_match(output)

If pandas dataframe, then use output.to_csv() since assert_match() accepts strings, not bytes

pytest --snapshot-update

simple server

python -m SimpleHTTPServer <port_number> -d <dir>

unused dependencies

Tool to identify unused deps

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment