title: Pytest: accessing a fixture from an outside function
body: <p>I would like to know if there is a way to access a pytest fixture from functions located in other modules. I wonder if I could use  custom pytest hooks for this.</p>
  
  <pre><code># test/test_file.py
  
  pytest.fixture
  def my_fixture()
     return my_object
  
  
  def test_function():
      print('Starting test)
      my_function('arg1')
  </code></pre>
  
  <pre><code># lib/functions.py
  
  def my_function(arg1):
      # I would like have access to my_fixture 
  
  </code></pre>
  
  <p>So since it's possible to access fixtures in pytest hooks during runtime session, I wonder if there is a way to access them from outside of the test functions also.</p>
  
  <p>So far this solution works for me:</p>
  
  <pre><code>@pytest.mark.hookwrapper
  def pytest_runtest_makereport(self, item, call):
      # Stops at first non-None test result
      outcome = yield
      rep = outcome.get_result()
      if rep.when == 'call' and hasattr(item, 'callspec'):
          test_case = item.callspec.params.get('test_case')
  </code></pre>
  
  <p>Here I can access <code>my_fixture</code> thingy, but only in a pre-defined hooks, pytest standard flow. I wonder if I could create my own hooks, and then make my functions "aware" of these and get the access to anything defined inside.</p>
  
  <p>How to define and use custom hooks?</p>