How to use exit_status method in yandex-tank

Best Python code snippet using yandex-tank

test_phone_book.py

Source:test_phone_book.py Github

copy

Full Screen

1import contextlib2import subprocess3import os4import pytest5@pytest.fixture6def no_db():7 with contextlib.suppress(Exception):8 os.unlink("directory.db")9def run_cmd(cmd):10 cmd = cmd.split()11 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)12 ret = p.wait()13 return ret, p.stdout.read().decode("ascii").strip()14def test_list_without_db(no_db):15 exit_status, op = run_cmd("./phone_book list")16 assert exit_status == 117 assert op == "Couldn't open database file: No such file or directory"18def test_search_without_db(no_db):19 exit_status, op = run_cmd("./phone_book search foo")20 assert exit_status == 121 assert op == "Couldn't open database file: No such file or directory"22def test_delete_without_db(no_db):23 exit_status, op = run_cmd("./phone_book delete foo")24 assert exit_status == 125 assert op == "Couldn't open database file: No such file or directory"26def test_adding_listing(no_db):27 exit_status, _ = run_cmd("./phone_book add john 1234567890")28 assert exit_status == 029 exit_status, _ = run_cmd("./phone_book add jack 0987654321")30 assert exit_status == 031 exit_status, _ = run_cmd("./phone_book add james 5432167890")32 assert exit_status == 033 exit_status, op = run_cmd("./phone_book list")34 assert exit_status == 035 expected = """john : 123456789036jack : 098765432137james : 543216789038Total entries : 3"""39 assert (op == expected)40def test_adding_searching_found(no_db):41 exit_status, _ = run_cmd("./phone_book add john 1234567890")42 assert exit_status == 043 exit_status, _ = run_cmd("./phone_book add jack 0987654321")44 assert exit_status == 045 exit_status, _ = run_cmd("./phone_book add james 5432167890")46 assert exit_status == 047 exit_status, op = run_cmd("./phone_book search john")48 assert exit_status == 049 expected = "1234567890"50 assert (op == expected)51def test_adding_searching_notfound(no_db):52 exit_status, _ = run_cmd("./phone_book add john 1234567890")53 assert exit_status == 054 exit_status, _ = run_cmd("./phone_book add jack 0987654321")55 assert exit_status == 056 exit_status, _ = run_cmd("./phone_book add james 5432167890")57 assert exit_status == 058 exit_status, op = run_cmd("./phone_book search wick")59 assert exit_status == 160 expected = "no match"61 assert (op == expected)62def test_adding_deleting_nonexistent(no_db):63 exit_status, _ = run_cmd("./phone_book add john 1234567890")64 assert exit_status == 065 exit_status, _ = run_cmd("./phone_book add jack 0987654321")66 assert exit_status == 067 exit_status, _ = run_cmd("./phone_book add james 5432167890")68 assert exit_status == 069 exit_status, op = run_cmd("./phone_book delete wick")70 assert exit_status == 171 expected = "no match"72 assert (op == expected)73def test_adding_deleting_first_list(no_db):74 exit_status, _ = run_cmd("./phone_book add john 1234567890")75 assert exit_status == 076 exit_status, _ = run_cmd("./phone_book add jack 0987654321")77 assert exit_status == 078 exit_status, _ = run_cmd("./phone_book add james 5432167890")79 assert exit_status == 080 exit_status, op = run_cmd("./phone_book delete john")81 assert exit_status == 082 exit_status, op = run_cmd("./phone_book list")83 assert exit_status == 084 expected = """jack : 098765432185james : 543216789086Total entries : 2"""87 assert (op == expected)88 89def test_adding_deleting_middle_list(no_db):90 exit_status, _ = run_cmd("./phone_book add john 1234567890")91 assert exit_status == 092 exit_status, _ = run_cmd("./phone_book add jack 0987654321")93 assert exit_status == 094 exit_status, _ = run_cmd("./phone_book add james 5432167890")95 assert exit_status == 096 exit_status, op = run_cmd("./phone_book delete jack")97 assert exit_status == 098 exit_status, op = run_cmd("./phone_book list")99 assert exit_status == 0100 expected = """john : 1234567890101james : 5432167890102Total entries : 2"""103 assert (op == expected)104 105def test_valgrind(no_db):106 run_cmd("./phone_book add john 1234567890")107 run_cmd("./phone_book add jack 0987654321")108 run_cmd("./phone_book add james 5432167890")109 exit_status, op = run_cmd("valgrind ./phone_book list")110 assert "All heap blocks were freed -- no leaks are possible" in op, "Memory is not being properly freed"111 112 ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run yandex-tank automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful