# Status of CustomExecutionTrait

**URL:** <https://forums.swift.org/t/status-of-customexecutiontrait/73358>\
**Category:** Swift Testing\
**Created:** [July 22, 2024, 2:31pm UTC](https://forums.swift.org/t/status-of-customexecutiontrait/73358 "2024-07-22T14:31:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbrandonw](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mbrandonw/32/349_2.png) [@mbrandonw](https://forums.swift.org/u/mbrandonw)\
**Post date:** [July 22, 2024, 2:31pm UTC](https://forums.swift.org/t/status-of-customexecutiontrait/73358/1 "2024-07-22T14:31:30Z")

</div>

We are busy updating our libraries to support swift-testing, and the last bit of functionality we see missing from XCTest is a way to wrap a test's execution in some additional work. For example, in our [SnapshotTesting](https://github.com/pointfreeco/swift-snapshot-testing) library we'd like to be able to enable a "record" mode for a single test or for a full test suite.

It seems that `CustomExecutionTrait` will be that feature for swift-testing, but I haven't seen much information on it since April. Is there anything new to share about its status? Is it planned for the first official release of swift-testing, both as an SPM package and the version included in Xcode?

---

<div class="post-metadata">

**Author:** ![mbrandonw](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mbrandonw/32/349_2.png) [@mbrandonw](https://forums.swift.org/u/mbrandonw)\
**Post date:** [July 29, 2024, 8:06pm UTC](https://forums.swift.org/t/status-of-customexecutiontrait/73358/2 "2024-07-29T20:06:47Z")

</div>

Just wanted to bump this in case it got lost.

---

<div class="post-metadata">

**Author:** ![grynspan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/grynspan/32/15315_2.png) [@grynspan](https://forums.swift.org/u/grynspan)\
**Post date:** [July 29, 2024, 10:21pm UTC](https://forums.swift.org/t/status-of-customexecutiontrait/73358/3 "2024-07-29T22:21:21Z")

</div>

It hasn't been, but the teammate best equipped to answer is out on leave. I'll ping folks.

---

<div class="post-metadata">

**Author:** ![briancroom](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/briancroom/32/22765_2.png) [@briancroom](https://forums.swift.org/u/briancroom)\
**Post date:** [July 30, 2024, 7:51pm UTC](https://forums.swift.org/t/status-of-customexecutiontrait/73358/4 "2024-07-30T19:51:46Z")

</div>

Hi @mbrandonw, thanks for your interest in `CustomExecutionTrait` and your patience on a reply.

Unfortunately, this experimental feature isn't going to make it into the first official Swift Testing release. We've been holding off on creating a `release/6.0` branch, but are expecting to do so in the very near future, with the work to [install Swift Testing into toolchains](https://github.com/apple/swift-testing/pull/581) as the only noteworthy item still planned, apart from any critical bug fixes. (We haven't been transparent enough about release planning this summer; that's something that we need to improve for future releases.)

Looking beyond the initial release, this would be a great feature to stabilize and promote to API for a following release. And I do think it's close! For next steps, we were still hoping to:

- Get feedback from experimental early adopters on how well the current interface serves the use case of applying pre- and post- actions to tests and suites. (It sounds like you have positive feedback already!)
  - One specific question I have is whether additional work is needed to allow a `CustomExecutionTrait` applied to a suite to execute its "before" and "after" logic around each child test, instead of only being able execute before and after the entire suite's execution.

- Consider whether this functionality should be rolled directly into the `Trait` protocol rather than needing an additional one.
- Bikeshed the spelling of whatever new interfaces we're proceeding with.
- Begin considering what _other_ kinds of custom traits we might want to provide in the future, and whether those future directions suggest adjustments to `CustomExecutionTrait`'s design.

With those learnings in hand, we should be able to run a [feature proposal](https://github.com/apple/swift-testing/blob/main/Documentation/Proposals/0000-proposal-template.md) to get things wrapped up. We'd love to get your feedback on any of the above, before we start writing that proposal!

---

<div class="post-metadata">

**Author:** ![mbrandonw](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mbrandonw/32/349_2.png) [@mbrandonw](https://forums.swift.org/u/mbrandonw)\
**Post date:** [July 31, 2024, 11:43am UTC](https://forums.swift.org/t/status-of-customexecutiontrait/73358/5 "2024-07-31T11:43:27Z")

</div>

Hi @briancroom, thanks for the update!

> [@briancroom](#):
>
> - 
> - One specific question I have is whether additional work is needed to allow a `CustomExecutionTrait` applied to a suite to execute its "before" and "after" logic around each child test, instead of only being able execute before and after the entire suite's execution.

From my experimentation it seemed like we were able to execute the work around each suite _and_ each test function by using `isRecursive = true`. Does this behave differently from what you are describing above?

* * *

I don't have any concrete feedback about the functionality of the trait. It serves the exact purpose we need, and without it our testing tools are going to be a lot more cumbersome to use. Each individual test function will need to be wrapped in a `withABC { … }` kind of configuration function, or people will need to use class-based (and `.serialized`) suites where they configure global variables in the `init`/`deinit`.

If there's anything we can do to help things along please feel free to reach out.

---

<div class="post-metadata">

**Author:** ![noremac](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/noremac/32/7222_2.png) [@noremac](https://forums.swift.org/u/noremac)\
**Post date:** [August 19, 2024, 1:55pm UTC](https://forums.swift.org/t/status-of-customexecutiontrait/73358/6 "2024-08-19T13:55:38Z")

</div>

Want to add a +1 that `CustomExecutionTrait`, exactly as it was (is!), was working well for me. I was using it to remove the boilerplate of setting some TaskLocals for the duration of a test.

---

<div class="post-metadata">

**Author:** ![grynspan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/grynspan/32/15315_2.png) [@grynspan](https://forums.swift.org/u/grynspan)\
**Post date:** [September 29, 2024, 2:30pm UTC](https://forums.swift.org/t/status-of-customexecutiontrait/73358/7 "2024-09-29T14:30:27Z")

</div>

My colleague @smontgomery is working on a [pitch](https://github.com/swiftlang/swift-testing/pull/733) right now! Formal pitch thread coming soon.

---

<div class="post-metadata">

**Author:** ![mbrandonw](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mbrandonw/32/349_2.png) [@mbrandonw](https://forums.swift.org/u/mbrandonw)\
**Post date:** [September 29, 2024, 2:56pm UTC](https://forums.swift.org/t/status-of-customexecutiontrait/73358/8 "2024-09-29T14:56:18Z")

</div>

This is wonderful! Eagerly looking forward to this…

---

<div class="post-metadata">

**Author:** ![smontgomery](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/smontgomery/32/965_2.png) [@smontgomery](https://forums.swift.org/u/smontgomery)\
**Post date:** [September 30, 2024, 10:10pm UTC](https://forums.swift.org/t/status-of-customexecutiontrait/73358/9 "2024-09-30T22:10:43Z")

</div>

The pitch is now posted, see [[Pitch] Custom Test Execution Traits](https://forums.swift.org/t/pitch-custom-test-execution-traits/75055).
