繁体   English   中英

在 Palantir Foundry 中,我怎样才能只在我的 Python Transform 的某些分支上运行测试?

[英]In Palantir Foundry, how can I only run tests on some branches of my Python Transform?

我的测试目前作为 Checks on each Commit 的一部分运行,但它们需要一段时间才能运行。 有没有办法只能在某些分支(例如,暂存分支)上运行测试?

Foundry 中的 PySpark 测试使用PyTest运行。 因此,您可以使用 PyTest 的内置功能来控制是否应该运行或跳过测试。

在 Foundry 中,您可以使用JEMMA_BRANCH环境变量在 Checks 中查看您的代码在哪个分支上运行(注意:此变量不会在构建期间设置,仅在检查中设置)。

结合 PyTest 的skipif标记,您可以将测试配置为仅在特定分支上运行,如下所示:

import os
import pytest


def only_run_on_branches(run_branches):
    current_branch = os.environ.get('JEMMA_BRANCH')

    return pytest.mark.skipif(
        current_branch not in run_branches and current_branch is not None,
        reason=f"Not running test on current branch ('{current_branch}')"
    )


@only_run_on_branches(["master"])
def test_increment():
    assert "testing" == "hard"

您可以在此处找到有关在 Foundry 中测试 PySpark 的更多文档,以及在此处PyTest 中跳过测试的更多文档。 该页面还向您展示了如何基于任意逻辑跳过整个文件或目录。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM