title: Add PyTest fixtures to a test class using dependency injection
body: <p>I'm using Python 3 with PyTest and have defined a number of fixture objects in <code>conftest.py</code>. The problem I'm having is that there are some fixture objects that will be needed by every test case. Requesting these fixture references in all test cases results in a lot of repeated boilerplate code.</p>
  <p>Here's the fixture in <code>conftest.py</code>:</p>
  <pre class="lang-py prettyprint-override"><code>def fixtureA(request):
      _fixture = FixtureA()
      # initialize the fixture, do stuff with request
      return _fixture
  </code></pre>
  <p>Here's the current test class, where I want to remove all fixtures from arguments for readability:</p>
  <pre class="lang-py prettyprint-override"><code>class TestSomeFeature(BaseTest):
  
      def test_some_function(self, fixtureA, fixtureB, fixtureC):
          fixtureA.doSomething()
          # execute test case, do stuff with other fixtures     
  
      def test_some_other_function(self, fixtureA, fixtureB, fixtureC):
          data = fixtureB.getData()
          # execute test case
  </code></pre>
  <p>This approach works, but I'd like to find a way to use dependency injection (or similar) to automagically inject the fixtures in <code>BaseTest</code> attributes without having to specify them in every test case's argument list. I'm looking for something like this, but open to any other suggestions:</p>
  <pre class="lang-py prettyprint-override"><code>class BaseTest:
      # This does not work, since pytest does not allow constructors in the test class
      def __init__(fixtureA, fixtureB, fixtureC):
          self.fixtureA = fixtureA
          self.fixtureB = fixtureB
          self.fixtureC = fixtureC
  </code></pre>
  <p>I want the test class to look like this, much cleaner!</p>
  <pre class="lang-py prettyprint-override"><code>class TestSomeFeature(BaseTest):
  
      def test_some_function(self):
          self.FixtureA.doSomething()
          # execute test case
  
      def test_some_other_function(self):
          data = self.FixtureB.getData()
          # execute test case
  </code></pre>