This is a bats test script I wrote
    export UUID=$(openssl rand -hex 6)
    export TEST_NAME=SecretsManagerTest1-$UUID
    setup_file() {
       echo "test name is $TEST_NAME" > setup.txt
    }
    
    @test "addition using bc" {
       echo "test name is $TEST_NAME" > runtest.txt
    }
I want $TEST_NAME to have the same value in setup.txt and runtest.txt but they have different UUIDS(same prefix - SecretsManagerTest1)
How can I accomplish this?
                        
When
batsruns a test suite, it executes a file multiple times, once per test, since each test has its own shell, and once forsetup_file.This in turn means, that the whole file will be
sourceseveral times, executing the "free code" outside any functions each time.If you want to retain the same UUID for all tests in a
.batsfile, you should move the UUID generation intosetup_file. Note thatsetup_filevariable that should be visible to the tests must beexported, since the tests run in a subshell.