简体   繁体   English

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

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

My tests currently run as part of Checks on every Commit, but they take a while to run.我的测试目前作为 Checks on each Commit 的一部分运行,但它们需要一段时间才能运行。 Is there a way I can only run the tests on certain branches (eg, a staging branch)?有没有办法只能在某些分支(例如,暂存分支)上运行测试?

PySpark tests in Foundry run using PyTest . Foundry 中的 PySpark 测试使用PyTest运行。 As a result, you can use PyTest's built-in functionality to control whether a test should run or be skipped.因此,您可以使用 PyTest 的内置功能来控制是否应该运行或跳过测试。

In Foundry, you can see which branch your code is running on in Checks using the JEMMA_BRANCH environment variable (nb: this variable won't be set during a Build, only in checks).在 Foundry 中,您可以使用JEMMA_BRANCH环境变量在 Checks 中查看您的代码在哪个分支上运行(注意:此变量不会在构建期间设置,仅在检查中设置)。

Combining this with PyTest's skipif mark, you can configure your tests to only run on particular branches as follows:结合 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"

You can find more documentation on testing PySpark in Foundry here , and on skipping tests in PyTest here .您可以在此处找到有关在 Foundry 中测试 PySpark 的更多文档,以及在此处PyTest 中跳过测试的更多文档。 That page also shows you how you can skip entire files or directories based on arbitrary logic, too.该页面还向您展示了如何基于任意逻辑跳过整个文件或目录。

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

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