kaste / PyTest

pytest runner and view annotator for sublime text
21 stars 6 forks source link

fix an issue relating to "focus test" #4

Closed zhanglix closed 7 years ago

zhanglix commented 7 years ago
kaste commented 7 years ago

Please provide more info on both bugs issues. Do you have a fix to come for the second issue, because just adding a comment does not look good to me.

On the first bug, can you post the significant portion of the XML test result, and maybe even parts of the actual test file. May be we/I should write some tests for this function.

zhanglix commented 7 years ago

sorry for the delay. When there are more than two tests fail which do not belong to any TestClass, click the focus button will not work as expected.

for example:

def test_1():
    assert 0

def test_2():
    assert 0

first run

xml output

<?xml version="1.0" encoding="utf-8"?><testsuite errors="0" failures="2" name="pytest" skips="0" tests="2" time="0.051"><testcase classname="arithmetic.tests.test" file="arithmetic/tests/test.py" line="2" name="test_1" time="0.001310110092163086"><failure message="assert 0">def test_1():
&gt;    assert 0
E    assert 0

arithmetic/tests/test.py:4: AssertionError</failure></testcase><testcase classname="arithmetic.tests.test" file="arithmetic/tests/test.py" line="5" name="test_2" time="0.00036716461181640625"><failure message="assert 0">def test_2():
&gt;    assert 0
E    assert 0

click focus console output

Run py.test --tb=auto -l /Users/zhangli/workshop/arithmetic/arithmetic/tests/test.py::::test_1
Traceback (most recent call last):
  File "pytest_exec in /Users/zhangli/Library/Application Support/Sublime Text 3/Installed Packages/PyTest.sublime-package", line 189, in parse_result
  File "src/lxml/lxml.etree.pyx", line 2452, in lxml.etree._Attrib.__getitem__ (src/lxml/lxml.etree.c:70080)
KeyError: 'line'

xml outputs

<?xml version="1.0" encoding="utf-8"?><testsuite errors="1" failures="0" name="pytest" skips="0" tests="1" time="0.241"><testcase classname="" file="" name="" time="0"><error message="collection failure">../../miniconda3/envs/school/lib/python3.6/site-packages/_pytest/runner.py:163: in __init__
    self.result = func()
../../miniconda3/envs/school/lib/python3.6/site-packages/_pytest/main.py:476: in _memocollect
    return self._memoizedcall(&apos;_collected&apos;, lambda: list(self.collect()))
../../miniconda3/envs/school/lib/python3.6/site-packages/_pytest/main.py:347: in _memoizedcall
    res = function()
../../miniconda3/envs/school/lib/python3.6/site-packages/_pytest/main.py:476: in &lt;lambda&gt;
    return self._memoizedcall(&apos;_collected&apos;, lambda: list(self.collect()))
../../miniconda3/envs/school/lib/python3.6/site-packages/_pytest/main.py:645: in collect
    for x in self._collect(arg):
../../miniconda3/envs/school/lib/python3.6/site-packages/_pytest/main.py:665: in _collect
    for x in self.matchnodes(self._collectfile(path), names):
../../miniconda3/envs/school/lib/python3.6/site-packages/_pytest/main.py:726: in matchnodes
    nodes = self._matchnodes(matching, names)
../../miniconda3/envs/school/lib/python3.6/site-packages/_pytest/main.py:738: in _matchnodes
    assert name
E   AssertionError</error></testcase></testsuite>

test_before_focus test_click_focus test_click_focus_console

zhanglix commented 7 years ago

about the second issue, it is just a warning, in case the root dir of pytest in not the root dir not the base_dir, i think it will fail to find the cases. so I think it is better to get the root dir from the output of py.text. 😃

kaste commented 7 years ago

Ok, got it. Released as 0.6.4 Thank you.