Changing phoenix url in tests?

I’m trying to write tests test for an application that needs to behave differently based on the hostname (e.g., subdomains) but this is causing problems.

The only way to make Phoenix aware of the change during the test run is to use AppWeb.Endpoint.config_change/2 but this is not playing nice. The change is leaking while other test modules are executing and it breaks their tests too.

Reverting the change directly or using an on_exit hook doesn’t work and neither does setting the test to async: false

Is there a good solution for this type of problem?