I have a simple code to check prod.py:
def add(x, y):
return x ** y
add(4.1, 4)
This is the test code test_prod.py:
from prod import add
import pytest
@pytest.mark.parametrize("a, b, expected", [(4, 4, 256), (2, 3, 8)])
def test_prod(a, b, expected):
assert add(a, b) == expected
@pytest.mark.parametrize("expected_exception, one, two", [(TypeError, 4, 'a'),])
def test_check(expected_exception, one, two):
with pytest.raises(expected_exception):
add(one, two)
Everything works well. But how do I check that the integer comes from prod.py ? In this code, prod.py returns a number with the float() data type. I need the test to fail. The test should end with success if prod.py will return int() .
I check the test like this: python3 -m pytest /home/user/test/test_prod.py -v
This doesn't work either because it doesn't check the real data type coming from prod.py::
from prod import add
import pytest
@pytest.mark.parametrize("a, b, expected", [(4, 4, 256), (2, 3, 8)])
def test_prod(a, b, expected):
assert add(a, b) == expected
if type(expected) is not int:
assert False
@pytest.mark.parametrize("expected_exception, one, two", [(TypeError, 4, 'a'),])
def test_check(expected_exception, one, two):
with pytest.raises(expected_exception):
add(one, two)
This code should NOT pass the test:
def add(x, y):
return x ** y
add(4.1, 4)
This code should pass the test:
def add(x, y):
return int(x ** y)
print(add(4, 4.1))