<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="307449" data-post-id="307449">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="gmile" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/gmile/120/33982_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  gmile
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Could you show a code snippet with example of how do you bypass with the config override? I want to try something similar, but I am not sure I am following the description</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="307449" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/bypass-and-async-tests-with-ex-unit/45005/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-307449" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="307449"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="307461" data-post-id="307461">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="ananthakumaran" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ananthakumaran/120/36597_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  ananthakumaran
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>The real implementation was a bit more complicated, but this covers the essential idea (untested). The test will call <code>MyConfig.register(app, key, url)</code> from the before callback (url constructed from the port obtained from bypass). The application code will call <code>MyConfig.get(app, key)</code> and the lookup call will return an overridden value if set, otherwise, will fall back to the Application.get_env. The lookup can handle Task.spawn etc, since most of them set $callers/$ancestors.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule MyConfig do
  def get(app, key) do
    if test? do
      case lookup({:__config_override, key}, [self()]) do
        nil -&gt; Application.get_env(app, key)
        value -&gt; value
      end
    else
      Application.get_env(app, key)
    end
  end

  def override(_app, key, value) do
    Process.put({:__config_override, key}, value)
  end

  defp lookup(key, list), do: lookup(key, list, MapSet.new())

  defp lookup(_key, [], _visited), do: nil

  defp lookup(key, [head | rest], visited) do
    if !MapSet.member?(visited, head) do
      case __get(head, key) do
        nil -&gt;
          list = Enum.concat([rest, __get(head, :"$callers", []), __get(head, :"$ancestors", [])])
          lookup(key, list, MapSet.put(visited, head))

        value -&gt;
          value
      end
    else
      lookup(key, rest, visited)
    end
  end

  defp __get(process, key), do: __get(process, key, nil)

  defp __get(process, key, default) when is_atom(process) do
    __get(Process.whereis(process), key, default)
  end

  defp __get(process, key, default) do
    {:dictionary, dictionary} = Process.info(process, :dictionary)
    :proplists.get_value(key, dictionary, default)
  end
end
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="307461" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/bypass-and-async-tests-with-ex-unit/45005/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-307461" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="307461"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>