title: Use pytest fixture in a function decorator
body: <p>I want to build a decorator for my test functions which has several uses. One of them is helping to add properties to the generated <code>junitxml</code>.</p>
  
  <p>I know there's a <a href="https://docs.pytest.org/en/latest/usage.html#record-property" rel="nofollow noreferrer">fixture</a> built-in pytest for this called <code>record_property</code> that does exactly that. How can I use this fixture inside my decorator?</p>
  
  <pre><code>def my_decorator(arg1):
      def test_decorator(func):
          def func_wrapper():
              # hopefully somehow use record_property with arg1 here
              # do some other logic here
              return func()
          return func_wrapper
      return test_decorator
  
  @my_decorator('some_argument')
  def test_this():
      pass # do actual assertions etc.
  </code></pre>
  
  <p>I know I can pass the fixture directly into every test function and use it in the tests, but I have a lot of tests and it seems extremely redundant to do this. </p>
  
  <p>Also, I know I can use <code>conftest.py</code> and create a custom marker and call it in the decorator, but I have a lot of <code>conftest.py</code> files and I don't manage all of them alone so I can't enforce it.</p>
  
  <p>Lastly, trying to import the fixture directly in to my decorator module and then using it results in an error - so that's a no go also.</p>
  
  <p>Thanks for the help</p>