def test_doubleit_type(): """This functions test whether the function fails right""" with pytest.raises(TypeError): myprogram.doubleit("hello")
def test_doubleit(): """This functions checks if the functions works fine""" assert myprogram.doubleit(10) == 20
import sys def doubleit(x): if not isinstance(x, (int,float)) var = x*2 return var if __name__ == '__main__': input_val = sys.argv[1] double_val = doubleit(input_val) print 'the value of {0} is {1}'.format(input_val, double_val) ###################################### # in a file called test_myprogram.py # ###################################### import myprogram import pytest def test_doubleit(): assert myprogram.doubleit(10) == 20 def test_doubleit_tyoe() with pytest.raises(TypeError): myprogram.doubleit('hello')
def test_doubleit(): assert myprogram.doubleit(10) == 20
def test_doubleit_type(): with pytest.raises(TypeError): # asserting a raised error, basically myprogram.doubleit('hello') print("Looking for an int, not a string!")
def test_doubleit_type(): with pytest.raises(TypeError): myprogram.doubleit('String')
def test_doubleit(): # This is the assert statement and it's a core we're doing here # We know that our doubleit function should give us number # multiplied by two. So assert statement should check if it's true assert myprogram.doubleit(10) == 20
def test_doubleit(self): assert myprogram.doubleit(10) == 20
def test_doubleit_type(): with pytest.raises(TypeError): myprogram.doubleit('5adsfsdf')
def test_doubleit_type(): with pytest.raises(TypeError): myprogram.doubleit('hello')
def test_doubleit_type(self): """ test doubleit() type safety """ with pytest.raises(TypeError): myprogram.doubleit('hello')
def test_doubleit_value(self): """ test doubleit() basic behavior """ assert myprogram.doubleit(10) == 20
def test_doublelit(): assert myprogram.doubleit(10) == 20
def test_doubleit_value(self): assert myprogram.doubleit(10) == 20
def test_doubleit(self): assert (myprogram.doubleit(10) == 20)
def test_doubleit_type(self): with pytest.raises(TypeError): myprogram.doubleit("Hello")
def test_doubleit_type(self): with pytest.raises(TypeError): # function rises exception myprogram.doubleit("hello")
def test_doubleit_type(self): with pytest.raises(TypeError): myprogram.doubleit('hi')
def test_doubleit(): assert myprogram.doubleit(10) == 20 a = myprogram.doubleit(10) print("Double it = " + str(a))