Errors with pytest
<p>I am using @pytest.mark.parametrize with various testcases and expected outputs. Its passing perfectly fine with few test cases and giving this error with some other cases. Not even able to google it. I want to know what could have gone wrong. I would be glad if someone can tell me how to atleast google for this error !</p>

<blockquote>
  <p>============================= test session starts =============================
  platform win32 -- Python 2.7.12, pytest-3.0.3, py-1.4.31, pluggy-0.4.0 -- c:\python27\python.exe</p>
  
  <p>cachedir: .cache</p>
  
  <p>rootdir: C:\Python27, inifile:</p>
  
  <p>collected 0 items / 1 errors</p>
  
  <p>=================================== ERRORS ====================================</p>
  
  <p>___________________ ERROR collecting test_mod_pppoe_disc.py ___________________</p>
  
  <p>lib\site-packages\py_path\local.py:650: in pyimport</p>
  
  <p><strong>import</strong>(modname)</p>
  
  <p>lib\site-packages\pytest-3.0.3-py2.7.egg_pytest\assertion\rewrite.py:131: in find_module</p>
  
  <p>source_stat, co = _rewrite_test(self.config, fn_pypath)</p>
  
  <p>lib\site-packages\pytest-3.0.3-py2.7.egg_pytest\assertion\rewrite.py:322: in _rewrite_test</p>
  
  <p>tree = ast.parse(source)</p>
  
  <p>lib\ast.py:37: in parse</p>
  
  <p>return compile(source, filename, mode, PyCF_ONLY_AST)</p>
  
  <p>E   ValueError: invalid \x escape</p>
  
  <p>!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!
  =========================== 1 error in 0.21 seconds ===========================</p>
</blockquote>

<pre><code>@pytest.mark.parametrize("test_input1,test_input2,expected", [
(ARP(sha='D\x85\x00\xa2}\xad', spa='\n\xc4@=', tha='\x00\x00\x00\x00\x00\x00', tpa='\n\xc4@\x01'),"&lt;socket._socketobject object at 0x0000000003DC8118&gt;",0),
(ARP(sha='jrofalfeoiexad', spa='\nenkajf@=', tha='\x00\x00\x00\x02jfcalkfel', tpa='\n\xcjfeiafa1'),"&lt;socket._socketobject object at 0x0000000003D2BD48&gt;",0),
(ARP(eioakn iejfoeajoijea),"&lt;socket._socketobject object at 0x0000000003DC8118&gt;",0)
])
def test_mod_arp(test_input1,test_input2,expected):
    assert mod_arp(test_input1,test_input2) == expected
</code></pre>

<p>Description about code: This is the code where I was getting error. I have appropriate functions defined. Working fine with first test case. Was failing with last two test cases.</p>

<p>The example you pasted can be minimized a bit into this file:</p>

<pre><code>import pytest

@pytest.mark.parametrize("foo", ['\n\xcjfeiafa1'])
def test_escapes(foo):
    pass
</code></pre>

<p>Which gives us the same error with Python 2, and a clearer error with Python 3:</p>

<pre><code>/usr/lib/python3.5/site-packages/_pytest/python.py:410: in _importtestmodule
    mod = self.fspath.pyimport(ensuresyspath=importmode)
/usr/lib/python3.5/site-packages/py/_path/local.py:650: in pyimport
    __import__(modname)
E     File "/home/florian/tmp/foo.py", line 3
E       @pytest.mark.parametrize("foo", ['\n\xcjfeiafa1'])
E                                       ^
E   SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-4: truncated \xXX escape
</code></pre>

<p>The reason this happens is due to your <code>\xcj</code> escape, which is not a valid escape. </p>

python py.test