Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 当需要预先加载模块时,在VS代码中运行pytest_Python_Visual Studio Code_Pytest - Fatal编程技术网

Python 当需要预先加载模块时,在VS代码中运行pytest

Python 当需要预先加载模块时,在VS代码中运行pytest,python,visual-studio-code,pytest,Python,Visual Studio Code,Pytest,我试图在VS代码中使用pytest,运行在red hat linux中。我使用的环境意味着我需要在运行pytest之前加载模块。在终端中,我可以运行: module load pandas pytest 测试成功运行。我可以在标准终端、VS代码中的Python调试控制台和VS代码中的int he bash终端中执行此操作。但是,如果我在VS代码中按下“运行所有测试”按钮,那么我只会得到一个错误,告诉我它找不到pandas模块 在运行pytest之前,我如何告诉测试环境运行我的模块加载命令?在这

我试图在VS代码中使用
pytest
,运行在red hat linux中。我使用的环境意味着我需要在运行
pytest
之前加载模块。在终端中,我可以运行:

module load pandas
pytest
测试成功运行。我可以在标准终端、VS代码中的Python调试控制台和VS代码中的int he bash终端中执行此操作。但是,如果我在VS代码中按下“运行所有测试”按钮,那么我只会得到一个错误,告诉我它找不到pandas模块


在运行pytest之前,我如何告诉测试环境运行我的
模块加载
命令?

在这种情况下,我将在包含测试的目录中创建一个名为
conftest.py
的文件。pytest在运行测试之前自动执行此文件。在这个文件中,您可以让Python执行shell命令。对于后者,有不同的选择,但请先尝试

有关
conftest.py
的更多信息:


太好了,谢谢!我最终使用了conda,并将python解释器设置为conda解释器。