Change assets naming method#199
Conversation
|
Without hashing you would expect the assets to be overwritten each time the tests are run. I'm fine with an option to prevent hashing, but I'm not a fan of lots of command line arguments. Perhaps this could be a config option or environment variable instead? |
|
Ok, how about something like this? |
|
Hey @SunInJuly I think a good way of doing that is with Pytest-metadata, which is a plugin that you can set metadata info to your pytest (@davehunt tell me if I'm wrong). But I think I got a better ideia for this issue. What do you think of the name of the assets being the unhashed name plus the hash? Something like "test01_fail_testname_[hash].png", it would solve your issue plus not having the issue of overwriting the assets every time the tests are run. |
|
Hey @RibeiroAna! |
|
Hi @SunInJuly ! Instead of hard coding the default config value for hasing, I would add it, like @davehunt suggested, as an optional ini-value instead. More info here FWIW I don't think pytest-metadata is the right way to go. The values there are meant to represent, well, meta data, surrounding the test/suite. Like what platform the tests were run on, browser used etc. Config stuffs (like this) I would say belong more in .cfg/.ini files. :) |
|
Thanks @BeyondEvil for the information! I was not so sure about my suggestion btw |
I like this suggestion, it keeps the hashes but also makes the file names more descriptive, and the best thing is there's no new configuration to document! 😄 |
|
I think there are enough tumbs up for my suggestion! So I think we won't need a configuration file, we can do just as I suggested. @SunInJuly could you update the PR? 😀 |
|
Yep! Here is what I came up with so far. Maybe you have tips for these tests? I'm working on it! FAILED testing/test_pytest_html.py::TestHTML::test_extra_image_separated_rerun[png-image] |
|
Ok I got this! Tests are fixed! |
| 'test_pass00') | ||
| hash_generator = hashlib.md5() | ||
| hash_generator.update(hash_key) | ||
| hash_generator.update(hash_key.encode('utf-8')) |
There was a problem hiding this comment.
I didn't get why you moved the econding from line 386 to here.
There was a problem hiding this comment.
I did the same thing in plugin.py.
This way filename is just more clear. Without it filename would be something like:
b'test_name'_[hash].png
I wanted to remove useless "b" and single quotes
There was a problem hiding this comment.
Gotcha! I think your PR is nice!
There was a problem hiding this comment.
wow, thanks! ^_^
RibeiroAna
left a comment
There was a problem hiding this comment.
@davehunt @BeyondEvil I approve @SunInJuly's PR, could any of you give a second look and merge it?
Hey, I did it too early! Could you solve Flake8 issues before? https://travis-ci.org/pytest-dev/pytest-html/jobs/494983199
|
@RibeiroAna fixed it! |
davehunt
left a comment
There was a problem hiding this comment.
This looks great, thanks for the enhancement @SunInJuly!
|
Nice! Good job, @SunInJuly ! 👍 |
|
Thank you all, for being so helpful and supportative ^_^ |
A little context:
I've been using pytest_html for layouts testing, sometimes reports contains about 100 mb of images, which is hard to navigate in browser. It would be nice if I could just scroll throw my assets and watch which test-case was failed in my file manager.
I found out that assets naming contains exact info I need, but in some reason it hashed.
So I added an option assets_name_hashing. When it's set False, assets names are not hashed and can be sorted nicely in folder.
What do you think?
Update:
now all assets named like "test_name_[hash].jpg"