如何 运行 在 Eclipse 上进行 pytest?
How to run pytest on Eclipse?
我是单元测试的新手,“我正在尝试在 Eclipse 上 运行 a pytest
。我已经搜索了几个小时,但似乎无法找出问题所在。我使用 https://pytest.org 网站上的简单示例。我的问题是 pytest
在 Eclipse 上没有 运行。我可以使用命令提示符进行测试,但我会而是在控制台上显示结果 window。
我尝试过但没有奏效的事情;
- 设置
PyUnit
测试运行ner到Py.test
运行ner(而不是默认的Pydev测试运行ner)
在这种情况下,我收到以下错误消息
usage: runfiles.py [options] [file_or_dir] [file_or_dir] [...]
runfiles.py: error: unrecognized arguments: --verbosity inifile:
None rootdir: C:\peepee\pytest\testing
- 我已将详细程度设置为 9(在某处读到它是最大值)。没有任何区别。
我正在尝试从 http://pytest.org 网站测试的简单代码
def func(x):
return x + 1
def test_answer():
assert func(3) == 5
通过 cmd 工作,但不能在 Eclipse 上工作。
请帮忙,因为我正在浪费时间来解决这个问题。提前致谢
找到替代方案。只需使用 PyCharm IDE 这使得 pytest 非常容易 运行。确保在 运行 进行任何测试之前进行以下配置。
- 单击 "Run" 选项卡。 Select"Edit configurations"
- 添加带有“+”符号的配置
- Select"Python test"下那个"py.test"
- 确保填写 "Target" 路径和 "working directory"
快乐的日子。现在你有 pytest 运行 结果显示在控制台上 window
它对你不起作用,因为你在参数文本字段中留下了“--verbosity 0”。我不知道为什么它没有被 Eclipse 自动删除,但是当您更改 运行ner 时,您还必须更改参数以反映您首选的测试 运行ner(在本例中为 pytest)。
全球所有新配置:
- Window -> Preferences -> PyDev -> PyUnit
- Change the test runner to "py.test runner" and clear the parameters (or add the ones you prefer. Make sure they are valid flags for pytest.)
或者,如果您愿意,可以手动为每个新的 运行 配置
- Create a Python unittest run configuration
- Select the class you want to run and the project (if they are not already there)
- In the Arguments tab override the pyUnit preferences with a py.test runner (clean up the parameters and add whatever you want to add to pytest flags)
1) 从 运行 菜单打开 运行 配置
2) 右击python unittest 和select new 配置新配置
3) select 项目和主模块,select 包含您的测试用例的模块。
4) 在参数选项卡下,选中 'override pyunit preferences for this launch'。
5) select Py.test 运行ner 从下拉列表中。
6) 输入 --tb=short 和 --capture=no(可以根据用户偏好更改值)
7) 单击应用,然后单击 运行。
注意:如果您使用 django-configurations 进行设置,那么您必须将调试器配置的环境变量部分中的 DJANGO_CONFIGURATION 环境变量设置为您用于从命令行运行测试的任何变量.
我是单元测试的新手,“我正在尝试在 Eclipse 上 运行 a pytest
。我已经搜索了几个小时,但似乎无法找出问题所在。我使用 https://pytest.org 网站上的简单示例。我的问题是 pytest
在 Eclipse 上没有 运行。我可以使用命令提示符进行测试,但我会而是在控制台上显示结果 window。
我尝试过但没有奏效的事情;
- 设置
PyUnit
测试运行ner到Py.test
运行ner(而不是默认的Pydev测试运行ner)
在这种情况下,我收到以下错误消息
usage: runfiles.py [options] [file_or_dir] [file_or_dir] [...] runfiles.py: error: unrecognized arguments: --verbosity inifile: None rootdir: C:\peepee\pytest\testing
- 我已将详细程度设置为 9(在某处读到它是最大值)。没有任何区别。
我正在尝试从 http://pytest.org 网站测试的简单代码
def func(x):
return x + 1
def test_answer():
assert func(3) == 5
通过 cmd 工作,但不能在 Eclipse 上工作。
请帮忙,因为我正在浪费时间来解决这个问题。提前致谢
找到替代方案。只需使用 PyCharm IDE 这使得 pytest 非常容易 运行。确保在 运行 进行任何测试之前进行以下配置。
- 单击 "Run" 选项卡。 Select"Edit configurations"
- 添加带有“+”符号的配置
- Select"Python test"下那个"py.test"
- 确保填写 "Target" 路径和 "working directory"
快乐的日子。现在你有 pytest 运行 结果显示在控制台上 window
它对你不起作用,因为你在参数文本字段中留下了“--verbosity 0”。我不知道为什么它没有被 Eclipse 自动删除,但是当您更改 运行ner 时,您还必须更改参数以反映您首选的测试 运行ner(在本例中为 pytest)。
全球所有新配置:
- Window -> Preferences -> PyDev -> PyUnit
- Change the test runner to "py.test runner" and clear the parameters (or add the ones you prefer. Make sure they are valid flags for pytest.)
或者,如果您愿意,可以手动为每个新的 运行 配置
- Create a Python unittest run configuration
- Select the class you want to run and the project (if they are not already there)
- In the Arguments tab override the pyUnit preferences with a py.test runner (clean up the parameters and add whatever you want to add to pytest flags)
1) 从 运行 菜单打开 运行 配置
2) 右击python unittest 和select new 配置新配置
3) select 项目和主模块,select 包含您的测试用例的模块。
4) 在参数选项卡下,选中 'override pyunit preferences for this launch'。
5) select Py.test 运行ner 从下拉列表中。
6) 输入 --tb=short 和 --capture=no(可以根据用户偏好更改值)
7) 单击应用,然后单击 运行。
注意:如果您使用 django-configurations 进行设置,那么您必须将调试器配置的环境变量部分中的 DJANGO_CONFIGURATION 环境变量设置为您用于从命令行运行测试的任何变量.