Sessions are really tough when you're trying to unit test/mock them. I'm not sure how Fat-Free would handle it cause it's been a while, but my guess is you might need to reset session values at the beginning of your test and then recreate your session values. Sessions are not as fun because they are basically globals randomly getting injected into your app.
<?php
// if using phpunit
// ...code
public function setUp(): void {
Base::instance()->clear('SESSION');
}
public function testMyTest() {
Base::instance()->set('SESSION.error_message', 'my message');
$f3->mock('POST /someRoute');
}
// ...more code
Otherwise, since it looks like you have F3 tests, I would just reset the session at the top of the file and build it dynamically as you need it.
<?php
$f3->clear('SESSION');
$f3->set('SESSION.error_message', 'Some error');
$f3->mock('POST /someRoute');
$test->expect(!empty($f3->get('SESSION.error_message')), 'An error occured!');
$test->expect(str_contains($f3->get('RESPONSE'), 'alert-danger'), 'An error occured.');