Skip to content

Instantly share code, notes, and snippets.

@philschmid
Last active February 26, 2020 20:16
Show Gist options
  • Select an option

  • Save philschmid/d19bd027c88cb28c857f40f584b5ecdb to your computer and use it in GitHub Desktop.

Select an option

Save philschmid/d19bd027c88cb28c857f40f584b5ecdb to your computer and use it in GitHub Desktop.
Gist for using Unittest with Pytest

How to use Pytest

Structure

test/
-- test_add.py
src/
-- add.py

Execution

pytest

def add(a,b):
try:
return a+b
except Exception as e:
print(e)
raise(e)
import pytest
from src.add import add
### test Functions ####
def test_add():
assert add(5,5) == 10
def test_except():
with pytest.raises(Exception) as e_info:
add(1,'test')
def test_instance():
assert isinstance(add(5,5),int)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment