def test_sample_pytest_test():
assert 'HELLO' == 'hello'.upper()
python -m pytest sample_pytest_test.py
Output
=== test session starts ===
platform ...
rootdir: ... ,
inifile:
collected 1 item
sample_pytest_test.py . [100%]
=== 1 passed in 0.08 seconds ===
You can also run the sample test as shown below.
py.test sample_pytest_test.py
from proj.sample_module import add2num
class Testadd2num:
def test_sum_2pos_num(self):
assert add2num(6, 7)==13
def test_sum_1pos_and_1neg_num(self):
assert add2num(-10, 9)==-1
py.test -v test
- You can run a single test module in a package with the following command.
py.test -v test/test_module1.py
- You can also run a specific test class as shown below.
py.test -v test/test_module1.py::Testadd2num
- You can also run a specific test class method as
py.test -v test/test_module1.py::Testadd2num::test_sum_2pos_num
@pytest.mark.skip(reason for skipping)
def test_sample():
....
@pytest.mark.skip(reason for skipping)
def test_sample():
....
import pytest
def test_using_raises():
with pytest.raises(TypeError):
2+'3' == 5
No comments:
Post a Comment