This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from textwrap import dedent | |
def multiline_hello_world(): | |
print("hello") | |
print(" world") | |
def test_multiline_hello_world(capsys): | |
expected = dedent('''\ | |
hello | |
world |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# stick this in .bashrc or .zshrc | |
# create, activate, exit | |
function create { | |
if [[ $# -gt 0 ]] | |
then | |
virtualenv -p py39 venv -q --prompt "($1) " | |
else | |
virtualenv -p py39 venv -q | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# mcd: menu driven cd (intended for .bashrc) | |
function mcd { | |
PS3="Which directory: " | |
select d in '/some/common/path/i/use/'\ | |
'/another/common/path/'\ | |
'/and/so/forth/' | |
do | |
cd $d | |
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create virtual environment | |
# | |
function create { | |
echo "\ncreating virtual environment" | |
python -m venv venv --prompt ${PWD##*/} | |
echo "upgrading pip" | |
venv/Scripts/python.exe -m pip install -U pip | |
if [ -f requirements.txt ] | |
then | |
echo "installing dependencies from requirements.txt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
from main import fibonacci | |
@pytest.mark.parametrize('n, expected', | |
enumerate([1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144])) | |
def test_returns_correct_fibonacci_number(n, expected): | |
assert expected == fibonacci(n) | |
def test_raise_value_error_on_negative_input(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# report call duration as both setup and call duration | |
# "fixes" duration reports in both PyCharm and pytest-html | |
_node_times = {} | |
@pytest.hookimpl(tryfirst=True) | |
def pytest_runtest_logreport(report): | |
if report.when == 'setup': | |
_node_times[report.nodeid] = report.duration | |
if report.when == 'call': | |
report.duration = report.duration + _node_times[report.nodeid] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mport pytest | |
# ----------------------------------------- | |
# To Demonstrate numerical ids not working | |
# ----------------------------------------- | |
testdata = [( 1, 2), ( 2, 4)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(venv) $ pytest -v test_ids.py | |
============================= test session starts ============================== | |
platform darwin -- Python 3.5.2, pytest-3.0.0, py-1.4.31, pluggy-0.3.1 -- /Users/okken/projects/book/bopytest/Book/venv/bin/python3.5 | |
cachedir: ../.cache | |
rootdir: /Users/okken/projects/book/bopytest/Book/code/pytest/um_project, inifile: | |
collected 8 items | |
test_ids.py::test_ids_strings[a] PASSED | |
test_ids.py::test_ids_strings[b] PASSED | |
test_ids.py::test_ids_paramterized_function[<1>-<2>] PASSED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(venv) $ pytest -v test_ids.py | |
============================= test session starts ============================== | |
platform darwin -- Python 3.5.2, pytest-3.0.0, py-1.4.31, pluggy-0.3.1 -- /Users/okken/projects/book/bopytest/Book/venv/bin/python3.5 | |
cachedir: ../.cache | |
rootdir: /Users/okken/projects/book/bopytest/Book/code/pytest/um_project, inifile: | |
collected 8 items | |
test_ids.py::test_ids_strings[a] PASSED | |
test_ids.py::test_ids_strings[b] PASSED | |
test_ids.py::test_ids_paramterized_function[<1>-<2>] PASSED |