以下代码旨在使用pytest在Databricks笔记本中运行单元测试。
import pytest
import os
import sys
repo_name = "Databricks-Code-Repo"
# Get the path to this notebook, for example "/Workspace/Repos/{username}/{repo-name}".
notebook_path = dbutils.notebook.entry_point.getDbutils().notebook().getContext().notebookPath().get()
# Get the repo's root directory name.
repo_root = os.path.dirname(os.path.dirname(notebook_path))
# Prepare to run pytest from the repo.
os.chdir(f"/Workspace/{repo_root}/{repo_name}")
print(os.getcwd())
# Skip writing pyc files on a readonly filesystem.
sys.dont_write_bytecode = True
# Run pytest.
retcode = pytest.main([".", "-v", "-p", "no:cacheprovider"])
# Fail the cell execution if there are any test failures.
assert retcode == 0, "The pytest invocation failed. See the log for details."
此代码片段位于Databricks提供的指南中。但是,它会产生以下错误:
PermissionError: [Errno 1] Operation not permitted: '/Workspace//Repos/<email_address>/Databricks-Code-Repo/Databricks-Code-Repo'
此笔记本在Databricks Repos中。我还有另外两个笔记本:
functions
(这里我定义了三个数据转换函数);test_functions
(我已经在前面的笔记本中为每个数据转换函数定义了测试函数)。
我知道这个错误与权限有关,但我不知道是什么原因造成的。我将感谢您的任何建议。
1条答案
按热度按时间ffx8fchx1#
我知道这很傻,但我重新启动了群集,它工作了。