尽管有sys.path.append()或设置了PYTHONPATH,Azure DevOps管道-Python-ModuleNotFoundError [英] Azure DevOps Pipelines - Python - ModuleNotFoundError despite sys.path.append() or setting PYTHONPATH

查看:58
本文介绍了尽管有sys.path.append()或设置了PYTHONPATH,Azure DevOps管道-Python-ModuleNotFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的python应用程序运行一些测试,但是我无法正确设置路径,以便我的 test.py 可以找到它.

I'm trying to run some tests for my python application but I'm not able to set the path correctly so that my test.py can find it.

我的应用程序的结构如下:

My Application is structured like this:

repo/src/main/python/main_module
repo/tests/test.py

我的 test.py 看起来像这样:

import sys

sys.path.append(os.path.normpath('C:/repo/src/main/python'))
import main_module

现在,我想在Azure Pipelines中测试代码,因此首先我将存储库复制到位:

Now I want to test the code within Azure Pipelines, so first I copy the repo in place:

- powershell: |
    cd C:/
    mkdir repo
    cp -r -v $(src.repo)/* C:/repo/
  condition: eq( variables['Agent.OS'], 'Windows_NT' )

此后,我使用 tree 来测试所有内容是否正确复制.

After that I use tree to test if everything was copied correctly.

然后我只需调用以下命令即可运行测试脚本:

And then I simply run the test script by calling:

python C:/repo/tests/test.py

但这给了我一个 ModuleNotFoundError .

我还尝试通过PYTHONPATH设置我的 main_module 的路径,但这还是行不通的.

I've also tried setting the path to my main_module via PYTHONPATH but that's not working too.

是我错过了他们的东西,还是这是Azure Pipelines中的错误?

Is their something I missed or is this a bug within Azure Pipelines?

推荐答案

在与Azure DevOps支持人员交谈之后,我现在知道我的问题目前是DevOps-Pipelines中的错误.

After talking to the Azure DevOps Support, I now know that my issue is a bug within DevOps-Pipelines at the moment.

现在,我将在主模块旁边复制测试脚本,如果一切顺利,则在构建应用程序之前将其删除.

For now I'm going to copy my test-scripts next to my main module and delete them if everything was successful and before building the application.

这篇关于尽管有sys.path.append()或设置了PYTHONPATH,Azure DevOps管道-Python-ModuleNotFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆