Where to put variables "cleanup" method

For example, I have 3 requests.
3_requests
Each of them has it’s own bodies, pre-request scripts, tests…
During collection running I set some variables. In my case ‘collectionVariables’. At the end of collection run I want to ‘clean’ all variables with ’ pm.collectionVariables.clear();'.

My question is: Where to put this method/how to organize collection? From logical side it’s not part of any request but I need to run it somehow.

Tnx!

1 Like

Great question.

If you know that the 3rd request will always be executed last, put inside the “Tests” this clean-up part. As an alternative you can add a dummy Clean-up request (point it to example.com or somewhere) and add there any clean-up code that you have.

It depends how you are running the collection. When automating with Newman, this is not an issue anymore.

1 Like

Yes, my idea also was to put it in the last request and clear variables that way. :+1: