Skip to content

Commit 501b074

Browse files
authored
Merge pull request #406 from TypedDevs/codex/fix-test-doubles-issue-in-parallel-tests
Fix parallel test doubles
2 parents b426d7d + c9e8443 commit 501b074

3 files changed

Lines changed: 5 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
- Fix asserts on test doubles in subshell
6+
- Fix test doubles when running tests in parallel
67
- Allow interpolating arguments in data providers output
78

89
## [0.19.1](https://github.com/TypedDevs/bashunit/compare/0.19.0...0.19.1) - 2025-05-23

docs/test-doubles.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
When creating tests, you might need to override existing function to be able to write isolated tests from external behaviour. To accomplish this, you can use mocks. You can also check that a function was called with certain arguments or even a number of times with a spy.
44

5+
Temporary files created by spies are isolated per test run, so they work reliably when executing tests in parallel.
6+
57
## mock
68
> `mock "function" "body"`
79

src/runner.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function runner::run_test() {
141141
# race conditions when running tests in parallel.
142142
local sanitized_fn_name
143143
sanitized_fn_name="$(helper::normalize_variable_name "$fn_name")"
144-
export BASHUNIT_CURRENT_TEST_ID="${sanitized_fn_name}_$$"
144+
export BASHUNIT_CURRENT_TEST_ID="${sanitized_fn_name}_$$_$(random_str 6)"
145145

146146
local interpolated_fn_name="$(helper::interpolate_function_name "$fn_name" "$@")"
147147
local current_assertions_failed="$(state::get_assertions_failed)"
@@ -343,6 +343,7 @@ function runner::parse_result_parallel() {
343343
echo "$execution_result" > "$unique_test_result_file"
344344
}
345345

346+
# shellcheck disable=SC2295
346347
function runner::_extract_field_value() {
347348
local line=$1
348349
local key=$2

0 commit comments

Comments
 (0)