title: How to create an extended xfail marker for py.test?
body: <p>In <code>py.test</code> (version 4.6.2) you have a mark-decorator for a test to mark it as failed, e.g.</p>
  
  <pre><code>@pytest.mark.xfail
  def test1():
      return 1/0
  </code></pre>
  
  <p>It is also possible to verify the exception itself </p>
  
  <pre><code>@pytest.mark.xfail(raises=ZeroDivisionError)
  </code></pre>
  
  <p>but is it possible in some way to verify the error message itself? </p>
  
  <p>this is useful when you have a <code>HTTPError</code>, as there can be many reasons. And when you compare the error message itself you can be much more specific about when the test fails (e.g. distinguish a certain <code>Client Error</code> from a <code>Server Error</code>). </p>
  
  <p>I am using the following construct so far:</p>
  
  <pre><code>def test_fail_request(self):      
      with pytest.raises(requests.exceptions.HTTPError) as excinfo:
          response = requests.something
      assert '403 Client Error: Not Found' in str(excinfo.value)
  </code></pre>
  
  <p>but of course a test like the follows would be more readable, compact and correctly handled by <code>py.test</code>:</p>
  
  <pre><code> @pytest.mark.xfail(expected_error = "403 Client Error: Not Found"):
   def test_fail_request(self):      
      response = requests.something
  </code></pre>
  
  <p>Is there a way to implement this behavior/feature?</p>
  
  <p>To clarify, the last code example is expected to fail, but only when the error message contains a certain message (example: <code>400 Client Error: Bad Request</code>). In that case, the test will be reported as <code>XFAIL</code>. </p>
  
  <p>But if the test fails and creates a <em>different</em> error message (even for the same exception, but e.g. <code>500 Server Error</code> in the error message instead), the test must be reported as “unexpectedly passing” (<code>XPASS</code>).</p>