title: Pytest: run teardown once for all workers using pytest-xdist
body: <p>I have a pytest fixture that I need to run only once across all pytest workers.</p>
  <pre><code>@pytest.fixture(scope=&quot;session&quot;)
  @shared  # this will call setup once for all processes
  def cache(request):
      acc = Account(id=10)
      acc.create()
      request.addfinilizer(acc.delete)
      return acc
  
  
  def shared(func):
      @functools.wraps(func)
      def wrapper(*args, **kwargs):
          request = kwargs['request']
          root = request.config._tmp_path_factory.getbasetemp().parent
          filepath = root / &quot;shared&quot;
  
          with filelock.FileLock(f'{filepath}.lock'):
              if filepath.is_file():
                  result = json.loads(filepath.read_text())
              else:
                  result = func(*args, **kwargs)
                  filepath.write_text(json.dumps(result.id))
  
          return result
      return wrapper
  </code></pre>
  <p>I use the solution from <a href="https://pytest-xdist.readthedocs.io/en/latest/how-to.html?highlight=only%20once#making-session-scoped-fixtures-execute-only-once" rel="nofollow noreferrer">https://pytest-xdist.readthedocs.io/en/latest/how-to.html?highlight=only%20once#making-session-scoped-fixtures-execute-only-once</a> and it works fine for the pytest <code>setup</code> part, but the <code>teardown</code> part is called on every pytest process.</p>
  <p>It is possible to lock <code>pytest-xdist</code> teardown to run it only once after all pytest sessions are finished? I want to run teardown once for all workers.</p>