title: How to access the string in brackets used in parametrized pytest tests?
body: <p>When I have a parametrized <code>pytest</code> test like in the following case:</p>
  
  <pre><code>@parametrize('repetition', range(3))
  @parametrize('name', ['test', '42'])
  @parametrize('number', [3,7,54])
  def test_example(repetition, name, number):
      assert 1 = 1
  </code></pre>
  
  <p>the test runner prints out lines like follows:</p>
  
  <pre><code>tests\test_example.py:12: test_example[1-test-7]
  </code></pre>
  
  <p>where the parametrized values show up in the rectangular bracket next to the test functions name (<code>test_example[0]</code>). How can I access the content of the rectangular bracket (i.e. the string <code>0</code>) inside the test? I have looked at the <a href="http://pytest.org/latest/builtin.html#_pytest.python.FixtureRequest.node" rel="nofollow"><code>request</code></a>
  fixture, but could not find a suitable method for my needs. </p>
  
  <p>To be clear: Inside the test method, I want to print the string <code>1-test-7</code>, which pytest prints on the console.</p>
  
  <p>How can I access the string <code>1-test-7</code>, which <code>pytest</code> print out during a test?</p>
  
  <p>I do not want to create this string by myself using something like</p>
  
  <pre><code>print str(repetition)+"-"+name+"-"+str(number)
  </code></pre>
  
  <p>since this would change every time I add a new parametrized argument to the test method.</p>
  
  <p>In addition, if more complex objects are used in the parametrize list (like namedtuple), these objects are just references by a shortcut (e.g. <code>object1</code>, <code>object2</code>, ...). </p>
  
  <p><strong>Addendum</strong>: If I use the <code>request</code> fixture as an argument in my test method, I 'see' the string I would like to access when I use the following command</p>
  
  <pre><code>print request.keywords.node.__repr__()
  </code></pre>
  
  <p>which prints out something like</p>
  
  <pre><code>&lt;Function 'test_example[2-test-3]'&gt;
  </code></pre>
  
  <p>I am trying to find out how this method <code>__repr__</code> is defined, in order to access directly the string <code>test_example[2-test-3]</code> from which I easily can extract the string I want, <code>2-test-3</code> in this example.</p>