Skip to content
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

Add expand_logs ini option #808

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/pytest_html/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ def pytest_addoption(parser):
default="result",
help="column to initially sort on.",
)
parser.addini(
"expand_logs",
type="string",
default=False,
help="expand all logs by default.",
)
parser.addini(
"generate_report_on_test",
type="bool",
Expand Down
3 changes: 3 additions & 0 deletions src/pytest_html/report_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ def __init__(self, config):
initial_sort = config.getini("initial_sort")
self._data["initialSort"] = initial_sort

expand_logs = config.getini("expand_logs")
self._data["expandLogs"] = expand_logs

@property
def additional_summary(self):
return self._additional_summary
Expand Down
4 changes: 4 additions & 0 deletions src/pytest_html/scripts/datamanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class DataManager {
get initialSort() {
return this.data.initialSort
}

get expandLogs() {
return this.data.expandLogs
}
}

module.exports = {
Expand Down
6 changes: 6 additions & 0 deletions src/pytest_html/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {
getVisible,
getCollapsedIds,
setCollapsedIds,
getExpandLogs,
getSort,
getSortDirection,
possibleFilters,
Expand Down Expand Up @@ -47,10 +48,12 @@ const addItemToggleListener = (elem) => {

const renderContent = (tests) => {
const sortAttr = getSort(manager.initialSort)
const expandLogs = getExpandLogs(manager.expandLogs)
const sortAsc = JSON.parse(getSortDirection())
const rows = tests.map(dom.getResultTBody)
const table = document.getElementById('results-table')
const tableHeader = document.getElementById('results-table-head')
const clickEvent = new Event('click')

const newTable = document.createElement('table')
newTable.id = 'results-table'
Expand All @@ -70,6 +73,9 @@ const renderContent = (tests) => {
find('.logexpander', row).addEventListener('click',
(evt) => evt.target.parentNode.classList.toggle('expanded'),
)
if (expandLogs) {
find('.logexpander', row).dispatchEvent(clickEvent)
}
newTable.appendChild(row)
}
})
Expand Down
11 changes: 11 additions & 0 deletions src/pytest_html/scripts/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ const showCategory = (categoryToShow) => {
window.history.pushState({}, null, unescape(url.href))
}

const getExpandLogs = (expandLogs) => {
if (expandLogs === 'true') {
return true
}
if (expandLogs) {
return true
}
return false
}

const getSort = (initialSort) => {
const url = new URL(window.location.href)
let sort = new URLSearchParams(url.search).get('sort')
Expand Down Expand Up @@ -99,6 +109,7 @@ module.exports = {
showCategory,
getCollapsedIds,
setCollapsedIds,
getExpandLogs,
getSort,
setSort,
getSortDirection,
Expand Down