In Palantir Foundry, how can I only run tests on some branches of my Python Transform? - pytest

My tests currently run as part of Checks on every Commit, but they take a while to run. Is there a way I can only run the tests on certain branches (e.g., a staging branch)?

PySpark tests in Foundry run using PyTest. As a result, you can use PyTest's built-in functionality to control whether a test should run or be skipped.
In Foundry, you can see which branch your code is running on in Checks using the JEMMA_BRANCH environment variable (n.b.: this variable won't be set during a Build, only in checks).
Combining this with PyTest's skipif mark, you can configure your tests to only run on particular branches as follows:
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. That page also shows you how you can skip entire files or directories based on arbitrary logic, too.

Related

Store results of unit test run into variables

I have a TeamCity build configuration that builds a C# project, runs some unit tests, and then does some extra things. My question is: Can I get information about my unit test run stored into build configuration variables (i.e. how many tests were run, how many were successful, how many failed, how many were skipped) so that I can then check these variables in a PowerShell script in later build steps and perform different actions depending on how many tests have passed?
AFAIK the best way is to ask these information directly to teamcity server using its REST API (pay attention, maybe the build locator could be a little be tricly to be found, if the build is still running).
By other hand, you can parse your NUnit test result file (or files if you run more than one NUnit test runner step in your build) inside your build agent machine.

How to run automation scripts in particular order in CI pipeline with Azure DevOps?

I'm trying to run my selenium automation scripts in CI pipeline using Azure DevOps. I have configured Visual Studio test task to run my automation scripts by selecting test plan option.
Now it runs all my automation scripts which associates with test cases. But it does not take the order define in the test case.
How do we define the order to run test cases? Currently it is not running according to test cases order.
For Example:
I have test cases: Test A, test B, test C.
I want to run test in order B,C,A.
You may create a main test and use any order, something similar was considered here: Controlling execution order of unit tests in Visual Studio
try this
use TestNG annotations and run with Priority tag.

How to trigger tests related to a particular file on Scala SBT

I'm a JS developer and I'm learning Scala, I'm used to the Jest test framework, in JS, which allows you to watch changed files and run tests for the changed modules.
Is there something similar in Scala?
I know that I can do:
~test to watch all the files and trigger all the tests
~test package/test_class to watch all the files and trigger only the specified test class.
Thanks a lot
I think you're looking for testQuick:
The testQuick task, like testOnly, allows to filter the tests to run to specific tests or wildcards using the same syntax to indicate the filters. In addition to the explicit filter, only the tests that satisfy one of the following conditions are run:
The tests that failed in the previous run
The tests that were not run before
The tests that have one or more transitive dependencies, maybe in a different project, recompiled.
You can use it with ~ and filtering that you already know.

Change a value in a file and run all tests again

I wrote an integration test suite using NUnit. Since we're talking integration tests, test code uses configuration files, the file system, database and so on.
However, I noticed that it would be nice to change the test environment (i.e. change a value inside a configuration file - this would change the code behavior in some cases), and then run the full test suite again but using this new environment.
Is there a way to automate this using NUnit? I have code that updates the file, so if I can somehow set things up programatically, great.

TFS Check-in Policy for testing without vsmdi

In our msbuild script we can run unit tests without using the vsmdi file:
We would like to enforce tests to be run on check in. The "Testing policy" seems to require a .vsmdi file. Is there a way to do this without one?
The out-of-the-box testing policy simply checks for the presence of a TestResults folder that has been created since the last checkin, indicating that MSTest has been run. If it finds one it then scans the test results for a reference to the .vsmdi file that is mentioned.
You could write a custom policy that does much the same thing but instead of looking for a .vsmdi file in the test results look for something else as an indicator that tests you want run have actually been run (and that they pass).