# Where is the best place to set global functions for tests?

**URL:** <https://community.postman.com/t/where-is-the-best-place-to-set-global-functions-for-tests/7440>\
**Category:** Help Hub\
**Tags:** tests, global\
**Created:** [August 27, 2019, 1:25am UTC](https://community.postman.com/t/where-is-the-best-place-to-set-global-functions-for-tests/7440 "2019-08-27T01:25:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kristianbrasel](https://avatars.discourse-cdn.com/v4/letter/k/e99b99/32.png) [@kristianbrasel](https://community.postman.com/u/kristianbrasel)\
**Post date:** [August 27, 2019, 1:25am UTC](https://community.postman.com/t/where-is-the-best-place-to-set-global-functions-for-tests/7440/1 "2019-08-27T01:25:10Z")

</div>

I’m trying to set some global functions for my tests, right now I have them in the collection “Pre-request Scrips” however these get run every time I make a request. Is there another place to place them that would make more sense?

---

<div class="post-metadata">

**Author:** ![jetison](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/jetison/32/12_2.png) [@jetison](https://community.postman.com/u/jetison)\
**Post date:** [August 27, 2019, 10:31pm UTC](https://community.postman.com/t/where-is-the-best-place-to-set-global-functions-for-tests/7440/2 "2019-08-27T22:31:06Z")

</div>

Hi there @kristianbrasel

As you said, collection-level pre-request scripts will execute prior to every request in the collection. Similarly, you could run your scripts at the folder- or request-level. This controls your scope a bit, but it’s still not accessible “globally”.

It’s not quite recommended, however you can also save your function as a variable (global, environment, collection, or whatever scope you choose). And then `eval()` it when needed. This gives you a little more flexibility to control your scope and allows you to share with team members if you wanted to. For example, global variables are available within a workspace. Environment variables are portable across collections. And so on.

If none of this is quite what you’re looking for, feel free to chime in on [feature requests](https://github.com/postmanlabs/postman-app-support/labels/feature) with specifics of your use case, [like this](https://community.postman.com/t/implement-hooks-to-postman-to-improve-maintainability-of-test-collections-before-beforeeach-aftereach-etc/3778).
