plainas / tq

Perform a lookup by CSS selector on an HTML input
MIT License
236 stars 5 forks source link

Adding new option: --parent #14

Closed Lucas-C closed 6 years ago

Lucas-C commented 6 years ago

Hi.

I have this use case: after running my unit tests with pytest, I want to be able to re-run all failing tests.

The tests results are stored in a XML fil with the following structure:

<?xml version="1.0" encoding="utf-8"?>
  <testsuite errors="0" failures="6" name="pytest" skips="8" tests="199" time="19.940">
    <testcase classname="tests.test_api.TestFileSystem" file="tests/test_api.py" line="37" name="test_baseurl_feature_not_used" time="0.0588071346283"></testcase>
    <testcase classname="tests.test_api.TestFileSystem" file="tests/test_api.py" line="25" name="test_baseurl_feature_used" time="0.0237061977386"></testcase>
...
    <testcase classname="tests.test_healthcheck_full.TestHealthcheckFull" file="tests/test_healthcheck_full.py" line="9" name="test_healthcheck" time="0.0403769016266"><failure message="AssertionError: 7 != 8">...</failure></testcase>
...
</testsuite>

With this new tq option, I could do the following to rerun only the failed tests:

pytest -k "$(tq failure -p -a name < results.xml | awk 'NR>1{print(" or ")} {print}' ORS='')"
plainas commented 6 years ago

Can you explain what it should do?

Lucas-C commented 6 years ago

The "tq failure -p -a name < results.xml" command will list all attributes "name" of the "failure" parent elements (which are "testcase" elements).

Lucas-C commented 6 years ago

Closing as PR #15 has been merged Thank you @plainas !