databricks 中的单元测试笔记本

问题描述 投票:0回答:1

我在 repo /Workspace/Repos/temp/test1/sample.py 内的 test1 文件夹内创建了 test_example.py,如下所示:

def test_addition():
    assert 1 + 2 == 3

def test_subtraction():
    assert 5 - 3 == 2

我在 repo /Workspace/Repos/temp/test1/sample.py 内的 test1 文件夹中创建了sample.py,如下所示: 导入 pytest

test_file_path = '/Workspace/Repos/temp/test1/test_example.py'

# Run the test file with the specified arguments
retcode = pytest.main([test_file_path, '-v', '-p', 'no:cacheprovider'])

# Check the return code to see if the tests passed or failed
assert retcode ==0, 'the pytest invocation failed.see the log above for details.'

我想测试 test1 文件夹中包含所有单元测试文件的所有文件:

但出现错误:

OSError:[Errno 95]不支持操作:'/Workspace/Repos/temp/test1/pycache' =========================== 简短的测试摘要信息 =================== ========= 错误 test_example.py - OSError: [Errno 95] 不支持操作: '/Worksp... !!!!!!!!!!!!!!!!!!!!!已中断:收集期间出现 1 个错误!!!!!!!!!!!!!!!!!! ================================= 1.06 秒内出现 1 个错误 ============== ================= 输出[2]:

unit-testing databricks
1个回答
0
投票

在调用 pytest.main() 之前添加此行。并先导入sys库。

sys.dont_write_bytecode = True

这将跳过在 Databricks 中的只读文件系统上写入 pyc 文件。

© www.soinside.com 2019 - 2024. All rights reserved.