[英]Pytest, How do you test a function and not run the rest of the file
Pytest: I have a file large .py file with a main body and many functions. Pytest:我有一个包含主体和许多功能的大型 .py 文件。 Without editing it to another file how do you focus on a function and only test it without running or executing the whole .py file如果不将其编辑到另一个文件,您如何专注于一个函数并且只测试它而不运行或执行整个 .py 文件
You can add the function/class name after the file name with two colons.您可以在带有两个冒号的文件名后添加函数/类名。 eg例如
pytest test_abc.py::test_function
If you want to execute multiple functions/classes with pytest, you need to mention it separately.如果你想用pytest执行多个函数/类,需要单独提一下。 eg例如
pytest test_abc.py::test_function1 test_abc.py::test_function2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.