我知道這違反了要求/假定正確包裝Python生產(chǎn)代碼的任何最佳做法:在某些情況下,能夠在同一文件中定義生產(chǎn)和測試代碼可能會有所幫助(例如,在簡單腳本的情況下)。然后如何在文件中運(yùn)行所有或特定測試pytest?編輯-針對我的特定用例的解決方案:文件結(jié)構(gòu)<root>:pytest.iniscrip_with_tests.py的內(nèi)容pytest.ini:[pytest]python_files = script_with_tests.py的內(nèi)容script_with_tests.py:import pytest # this is not required, works without as welldef test_always_pass(): passif __name__ == "__main__": main()pytest調(diào)用<root>:pytest script_with_tests.py
添加回答
舉報
0/150
提交
取消