Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/user_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ URL ``extras.url('http://www.example.com/')``
Image ``extras.image(image, mime_type='image/gif', extension='gif')``
Image ``extras.image('/path/to/file.png')``
Image ``extras.image('http://some_image.png')``
Video ``extras.video(video, mime_type='video/webm', extension='webm')``
========== ============================================

**Note**: When adding an image from file, the path can be either absolute
Expand Down
2 changes: 1 addition & 1 deletion src/pytest_html/resources/index.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<div class="media-container__viewport">
<img src="" />
<video controls>
<source src="" type="video/mp4">
<source src="">
</video>
</div>
<div class="media-container__nav--right">&gt;</div>
Expand Down
4 changes: 2 additions & 2 deletions src/pytest_html/scripts/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ const dom = {
}

const media = []
extras?.forEach(({ name, format_type, content }) => {
extras?.forEach(({ name, format_type, content, mime_type }) => {
if (['image', 'video'].includes(format_type)) {
media.push({ path: content, name, format_type })
media.push({ path: content, name, format_type, mime_type })
}

if (format_type === 'html') {
Expand Down
5 changes: 5 additions & 0 deletions src/pytest_html/scripts/mediaviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ const setup = (resultBody, assets) => {
videoEl.classList.add('hidden')
} else if (media?.format_type === 'video') {
sourceEl.src = media.path
if (media.mime_type) {
sourceEl.type = media.mime_type
} else {
sourceEl.removeAttribute('type')
}

videoEl.classList.remove('hidden')
imageEl.classList.add('hidden')
Expand Down
12 changes: 10 additions & 2 deletions testing/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,13 @@ def pytest_runtest_makereport(item, call):
element = page.select_one(".media img")
assert_that(str(element)).is_equal_to(f'<img src="{src}"/>')

@pytest.mark.parametrize("mime_type, extension", [("video/mp4", "mp4")])
@pytest.mark.parametrize(
"mime_type, extension",
[
("video/mp4", "mp4"),
("video/webm", "webm"),
],
)
def test_extra_video(self, pytester, mime_type, extension):
content = str(random.random())
charset = "utf-8"
Expand All @@ -592,7 +598,9 @@ def pytest_runtest_makereport(item, call):
report = outcome.get_result()
if report.when == 'call':
from pytest_html import extras
report.extras = [extras.{extension}('{data}')]
report.extras = [
extras.video('{data}', mime_type='{mime_type}', extension='{extension}')
]
"""
)
pytester.makepyfile("def test_pass(): pass")
Expand Down