pytest-testcase

neevop 七月 3, 2023


basic test

def test_name():
	...
	assert ...

test assert

# equal
assert actual == excepted

# not equal
assert actual != excepted

# contains
assert value in collection

# not contains
assert value not in collection

# exception
with pytest.raises(Exception1):
	pass

expected exceptions

def test_recurion_depth():
	with pytest.raise(RuntimeError) as excinfo:
		def f():
			f()
		f()
	assert 'maximum recursion' in str(excinfo.vaule)

test using parameterize

import pytest 

@pytest.mark.parameterize(('n', 'excepted'), [
							(1, 2),
							(2, 3)
							(3, 4),
							pytest.mark.xfail((1, 0)),
							pytest.mark.xfail(reason="some bug", (1, 0)),
							pytest.mark.skipif('sys.version_info >= (3, 0)', (10, 11)),
						])
def test_increment(n, excepted):
	assert n + 1 == excepted