Python 3.x 如何要求Pytest在python脚本中运行特定测试?
如果我在一个脚本中运行多个测试,例如:Python 3.x 如何要求Pytest在python脚本中运行特定测试?,python-3.x,pytest,Python 3.x,Pytest,如果我在一个脚本中运行多个测试,例如: import pytest @pytest.mark.parametrize("test_input,expected", [ ("3+5", 8), ("2+4", 6), ("6*9", 42), ]) def test_eval(test_input, expected): assert eval(test_input) == expected @pytest.mark.parametrize('test_inpu
import pytest
@pytest.mark.parametrize("test_input,expected", [
("3+5", 8),
("2+4", 6),
("6*9", 42),
])
def test_eval(test_input, expected):
assert eval(test_input) == expected
@pytest.mark.parametrize('test_input,expected', [
(1,1),
(2,2),
(2,3),
])
def test_equal(test_input,expected):
assert test_input == expected
if __name__ == '__main__':
'''
Test Zone!
'''
#executing the tests
pytest.main([__file__])
如何使用最后一行pytest.main([\uu file\uu])
一次运行一个测试,而不是一次运行所有测试?使用pytest.main()
就像根据pytest从命令行调用pytest一样。您可以将命令和参数传递给此,允许您使用通过关键字表达式指定测试:
pytest.main(["-k", "test_func"])
您还可以通过以下方式指定测试:
pytest.main(["test_mod.py::test_func"])