Skip to content

Useful code examples and patterns that I continuously use and look up :)

Notifications You must be signed in to change notification settings

KantiCodes/Python-examples

Repository files navigation

Why this repo?

Because I keep solving the same problems over and over and then I endup trying to remember in which project is the solution located :)

Installation & usage

Ran on python 3.9.13 but any python3 should do.

First you need cd to the example that yo want to execute

Create a virtual environment

  • mac/linux python3 -m venv .venv
  • windows python -m venv .venv

Activate venv

  • mac/linux source .venv/bin/activate
  • windows .\venv\Scripts\activate

Install depedencies (on activated venv)

  • Either python -m pip install -r requirements.in
  • Or python -m pip install -r requirements.txt if I did put those in :D

Examples

Given a mocked object assert that it has many calls (in any order)

This examples targets command lines tools and shows how to enable a flag for verbose output of the error in the tool

Simple patching of modules during test

When the same method is supposed to return different things, one can patch it with iterable and allow each call to return something else

Example of a fixture that you insert into conftest.py that allows you to patch the database used by SUT for a different - test one.

About

Useful code examples and patterns that I continuously use and look up :)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages