title: How to skip a pytest using an external fixture?
body: <h1>Background</h1>
  
  <p>I am running a <a href="http://pytest.org/latest/">py.test</a> with a <a href="http://pytest.org/latest/fixture.html">fixture</a> in a <a href="http://pytest.org/latest/plugins.html#conftest-py-local-per-directory-plugins">conftest file</a>. You can see the code below(this all works fine):</p>
  
  <p><strong>example_test.py</strong></p>
  
  <pre><code>import pytest
  
  @pytest.fixture
  def platform():
      return "ios"
  
  @pytest.mark.skipif("platform == 'ios'")
  def test_ios(platform):
      if platform != 'ios':
          raise Exception('not ios')
  
  def test_android_external(platform_external):
      if platform_external != 'android':
          raise Exception('not android')
  </code></pre>
  
  <p><strong>conftest.py</strong></p>
  
  <pre><code>import pytest
  
  @pytest.fixture
  def platform_external():
      return "android"
  </code></pre>
  
  <h1>Problem</h1>
  
  <p>Now I want to be able to skip some tests that do not apply to my current test-run. In my example I am running tests either for <strong>iOS</strong> or <strong>Android</strong> (This is just for demonstration purposes only and could be any other expression).</p>
  
  <p>Unfortunately I cannot get ahold of (my <em>externally</em> defined <strong>fixture</strong>) <code>platform_external</code> in the <code>skipif</code> statement. When I run the code below I receive the following exception: <code>NameError: name 'platform_external' is not defined</code>. I don't know if this is a <strong>py.test</strong> bug as <em>locally</em> defined fixtures are working.</p>
  
  <p>add-on for <strong>example_test.py</strong></p>
  
  <pre><code>@pytest.mark.skipif("platform_external == 'android'")
  def test_android(platform_external):
      """This test will fail as 'platform_external' is not available in the decorator.
      It is only available for the function parameter."""
      if platform_external != 'android':
          raise Exception('not android')
  </code></pre>
  
  <p>So I thought I will just create my own <strong>decorator</strong>, just to see that it won't receive the fixtures as parameters:</p>
  
  <pre><code>from functools import wraps
  
  def platform_custom_decorator(func):
      @wraps(func)
      def func_wrapper(*args, **kwargs):
          return func(*args, **kwargs)
      return func_wrapper
  
  @platform_custom_decorator
  def test_android_2(platform_external):
      """This test will also fail as 'platform_external' will not be given to the 
      decorator."""
      if platform_external != 'android':
          raise Exception('not android')
  </code></pre>
  
  <h1>Question</h1>
  
  <p>How can I define a <strong>fixture</strong> in a <strong>conftest</strong> file and use it to (conditionally) <strong>skip a test</strong>?</p>