Skip to content

Commit 27b6e77

Browse files
SunInJulyRibeiroAna
authored andcommitted
Change assets naming method (#199)
* added assets name hashing option * from command line option to config option * new naming strategy * fix * Flake8 issues fixed * more Flake8 issues fixed
1 parent 703a5cc commit 27b6e77

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

pytest_html/plugin.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,14 @@ def __lt__(self, other):
145145

146146
def create_asset(self, content, extra_index,
147147
test_index, file_extension, mode='w'):
148+
148149
hash_key = ''.join([self.test_id, str(extra_index),
149-
str(test_index)]).encode('utf-8')
150+
str(test_index)])
150151
hash_generator = hashlib.md5()
151-
hash_generator.update(hash_key)
152-
asset_file_name = '{0}.{1}'.format(hash_generator.hexdigest(),
153-
file_extension)
152+
hash_generator.update(hash_key.encode('utf-8'))
153+
asset_file_name = '{0}_{1}.{2}'.format(hash_key,
154+
hash_generator.hexdigest(),
155+
file_extension)
154156
asset_path = os.path.join(os.path.dirname(self.logfile),
155157
'assets', asset_file_name)
156158
if not os.path.exists(os.path.dirname(asset_path)):

testing/test_pytest_html.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -383,12 +383,12 @@ def pytest_runtest_makereport(item, call):
383383
testdir.makepyfile('def test_pass(): pass')
384384
result, html = run(testdir)
385385
hash_key = ('test_extra_text_separated.py::'
386-
'test_pass00').encode('utf-8')
386+
'test_pass00')
387387
hash_generator = hashlib.md5()
388-
hash_generator.update(hash_key)
388+
hash_generator.update(hash_key.encode('utf-8'))
389389
assert result.ret == 0
390-
src = '{0}/{1}'.format('assets', '{0}.txt'.
391-
format(hash_generator.hexdigest()))
390+
src = '{0}/{1}'.format('assets', '{0}_{1}.txt'.
391+
format(hash_key, hash_generator.hexdigest()))
392392
link = ('<a class="text" href="{0}" target="_blank">'.format(src))
393393
assert link in html
394394
assert os.path.exists(src)
@@ -412,13 +412,12 @@ def pytest_runtest_makereport(item, call):
412412
""".format(extra_type, content))
413413
testdir.makepyfile('def test_pass(): pass')
414414
result, html = run(testdir)
415-
hash_key = ('test_extra_image_separated.py::'
416-
'test_pass00').encode('utf-8')
415+
hash_key = 'test_extra_image_separated.py::test_pass00'
417416
hash_generator = hashlib.md5()
418-
hash_generator.update(hash_key)
417+
hash_generator.update(hash_key.encode('utf-8'))
419418
assert result.ret == 0
420-
src = '{0}/{1}'.format('assets', '{0}.{1}'.
421-
format(hash_generator.hexdigest(),
419+
src = '{0}/{1}'.format('assets', '{0}_{1}.{2}'.
420+
format(hash_key, hash_generator.hexdigest(),
422421
file_extension))
423422
link = ('<a class="image" href="{0}" target="_blank">'.format(src))
424423
assert link in html
@@ -451,11 +450,12 @@ def test_fail():
451450

452451
for i in range(1, 4):
453452
hash_key = ('test_extra_image_separated_rerun.py::'
454-
'test_fail0{0}'.format(i)).encode('utf-8')
453+
'test_fail0{0}'.format(i))
455454
hash_generator = hashlib.md5()
456-
hash_generator.update(hash_key)
457-
src = 'assets/{0}.{1}'.format(hash_generator.hexdigest(),
458-
file_extension)
455+
hash_generator.update(hash_key.encode('utf-8'))
456+
src = 'assets/{0}_{1}.{2}'.format(hash_key,
457+
hash_generator.hexdigest(),
458+
file_extension)
459459
link = ('<a class="image" href="{0}" target="_blank">'.format(src))
460460
assert result.ret
461461
assert link in html

0 commit comments

Comments
 (0)