Skip to content

Filter the tests results by outcome #issue38 #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 20, 2016
Merged

Filter the tests results by outcome #issue38 #46

merged 12 commits into from
Jun 20, 2016

Conversation

RibeiroAna
Copy link
Member

How it looks: when the page is first loaded, there are checked check-boxes and by checking and unchecking the boxes, the users can filter which tests they want to see. If there are no tests of one outcome, the checkbox is disabled.

image screenshot

Corrected the problem of the run line
@davehunt
Copy link
Collaborator

@RibeiroAna you don't need to close and open new pull requests when you modify your code. If you push additional commits to the same branch, GitHub will show the changes in the open pull request. Once we're ready to merge we can squash the commits if needed.

html.td(additional_html, class_='extra')],
class_=result.lower() + ' results-table-row'))
html.td(additional_html, class_='extra', id=test_id)],
class_=result.lower() + ' results-table-row', id=test_id))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't have two elements with the same id.

The id global attribute defines a unique identifier (ID) which must be unique in the whole document.

From: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could consider using data attributes instead.

@davehunt
Copy link
Collaborator

In testing this, I'm unable to filter out errors. I suspect this is related to differences in the test id. Here are some examples for generating setup/teardown errors:

@pytest.fixture
def startup_error():
    raise Exception('startup_error')


def test_startup_error(startup_error):
    pass


@pytest.fixture
def teardown_error(request):
    def fin():
        raise Exception('teardown_error')
    request.addfinalizer(fin)


def test_teardown_error(teardown_error):
    pass

@@ -37,6 +48,7 @@ def assert_summary(html, tests=1, duration=None, passed=1, skipped=0, failed=0,
assert int(re.search('(\d)+ errors', html).group(1)) == errors
assert int(re.search('(\d)+ expected failures', html).group(1)) == xfailed
assert int(re.search('(\d)+ unexpected passes', html).group(1)) == xpassed
assert_summary_checkboxes(html, passed)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than call another method and only check passed, it wouldn't be much additional code to check all boxes are in the HTML and have the appropriate state. You could potentially use **kwargs to loop over the outcomes passed to this method and reduce duplication. You might then need a dict for mapping xfailed to expected failures, etc.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it may make sense to also add a test that opens the HTML report in a browser and verifies that toggling the checkboxes filters the results. This would have caught the issue I'm seeing with filtering errors.

@@ -215,23 +218,51 @@ def pytest_sessionfinish(self, session):
html.title('Test Report'),
html.style(raw(style_css)))


class ResultByType:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea if here would be the best place for a new class

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine. We could also move it to it's own file. In this case is the type the outcome? I'm a bit confused by the name of the class. This object represents each potential outcome, perhaps Outcome would be a better name?

@@ -141,21 +141,26 @@ def _appendrow(self, result, report):
log.append(html.br())
log.append(content)
else:
log = html.div(class_='empty log')
log = html.div(class_='empty log', colspan="5")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The colspan should be on the <td>, and not needed here.

@davehunt
Copy link
Collaborator

davehunt commented Jun 6, 2016

The sort is only working for me every other click. Also, could you add a message to the page when all results have been filtered out? I've added a few other comments, but this is looking great!


class TestHTML:
# Asserts by outcome
assert_results_by_outcome(html, 'passed', passed)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davehunt by doing that I don't have to write all the individual checks again


# Asserts number of rows of the table
assert len(re.findall('tbody', html)) or 0 == tests
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The or 0 should not be needed, as findall will return an empty list if there are no matches.

};
}

function key_num(col_index) {
return function(elem) {
return parseFloat(elem.childNodes[col_index].firstChild.data);
return parseFloat(elem.childNodes[1].childNodes[col_index].firstChild.data);
};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davehunt the problem was that before we had just one child (like, it was , but now it is first one about the rowlogs), so there was one more level to access.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha! I knew you'd work it out. 😀

label=None):
# Asserts if the test number of this outcome in the summary is correct
regex_summary = '(\d)+ {0}'.format(label or test_outcome)
int(re.search(regex_summary, html).group(1)) == test_outcome_number
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still missing an assert here.

@davehunt
Copy link
Collaborator

davehunt commented Jun 7, 2016

This is looking great, @RibeiroAna! Could you add a message to the table when the user filters all the results out? Just something like "No results? Try removing some of the filters." In a later enhancement we could even add a "clear all" link to the message to remove any applied filters.

@RibeiroAna
Copy link
Member Author

Hi @davehunt , I just put the "not found" message. We could open a new issue to "clear all" function and merge that one =)

@davehunt
Copy link
Collaborator

davehunt commented Jun 7, 2016

We could open a new issue to "clear all" function and merge that one =)

I agree. I'll look at your latest changes first thing tomorrow. Thanks!

});
function is_all_rows_hidden() {
var rows = find_all('.results-table-row');
if(rows.length == 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use a filter here, to reduce the array to only rows that are not hidden. Then you can just return the result of checking the length against zero.

@davehunt
Copy link
Collaborator

davehunt commented Jun 8, 2016

@RibeiroAna just three comments to address, and then I think we're ready to merge. Rather than waiting on me, please feel free to move onto #49 (which I think is a great idea), or #37.

@davehunt davehunt merged commit fb4d594 into pytest-dev:master Jun 20, 2016
denisra pushed a commit to denisra/pytest-html that referenced this pull request Nov 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants