Execute teardown() if something fails in setUp()

I experienced that teardown() doesn’t get executed if something fails in my setUp(), it only run if something fails in the default function(), but I really would like it to be executed if something in the setUp fails. I didn’t find any solution for it so far. Can you help me with this?

can someone maybe help me with this? Should I try to provide additional information?
In the setup I upload some files, and I also check if the upload is successful, and it is in the setup because these are basic files, that are needed for the tests, which work with these files… but I upload 3 files, and sometimes it happens that the first two files are successfully uploaded, but the third one is not, and in the teardown I delete these files, so that I would end up with the environment that I started with, so with no files. But the problem is, that if the upload of the third file fails in the setup, then the teardown doesn’t run, and the first two files do not get deleted. And I prefer to upload these files in the setup to upload them in the default function.
I would really appreciate your help.

Hi @Lilla, Welcome to the community forum!

This is mostly a design choice as there is no way to know if there will be anything to be done if the setup has not completed successfully. It also might mean that we get an error there as well for no reason other than the setup has failed.

You can open an issue with your case and we can discuss if this can/should be changed.

As a workaround I would recommend using try/catch as in:

export function setup() {
  try { 
  // do your request and throw an exception on error 
  } catch (e) {
    //you can log e for example
    throw e; // so we do actually abort the execution after all.
export teardown function() {
  // do what you need.

Hope this helps you