【问题标题】:In PyCharm, how do you add a custom parameter to pytest when running unittests?在 PyCharm 中,如何在运行 unittests 时向 pytest 添加自定义参数?
【发布时间】:2019-06-24 07:27:34
【问题描述】:

我正在 pycharm 中运行 Python 单元测试。这会执行命令:

/<path>/python /<path>/_jb_pytest_runner.py --target my_function_test_base.py::MyFunctionTestBase

在 //tests 中使用参数 my_function_test_base.py::MyFunctionTestBase 启动 pytest

我想添加我在此答案中找到的 pytest 选项 --tb=1Make Python unittest show AssertionError but no Traceback

我不知道如何在 PyCharm 下做到这一点。

【问题讨论】:

  • 为什么这是不可能的 Edit Configurations 然后添加任何你想要的参数?
  • 我看到Additional Arguments(我相信的测试用例的参数)和Interpreter options(python 解释器的参数)。但是那里没有任何东西可以让我向 pytest 发送参数。我错了吗?
  • Additional Arguments 确实是pytest 的参数,试一试。
  • 啊,谢谢帕维尔,你说得对!我滥用了这个论点,这让我认为这些论点没有出现在正确的地方。您应该将其发布为答案。

标签: python unit-testing pycharm


【解决方案1】:

代表 cmets 回答,实际上 Edit Configurations 部分中的 Additional Arguments 确实将参数传递给 py.test。我的错误在于滥用其中一个参数,混淆了Additional Arguments 按预期传递参数的事实。

【讨论】:

    猜你喜欢
    • 2020-04-25
    • 1970-01-01
    • 2022-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多