Remove timestamp and test path from screenshot names.

Hopefully now that we have reporting in the test results, and pytest
retaining of old directories, we don't have to encode so much
information in the filenames to help you make sense of them.

Previously the png filenames looked like this:

    2024-08-24T12_42_11.160556-tests_end2end_features_test_completion_bdd.py__test_deleting_an_open_tab_via_the_completion.png

Now they just have the individual test name, eg:

    test_deleting_an_open_tab_via_the_completion.png

The two times people will want to look at these files and I want to make
sure they can find what they are looking for are:

* running the tests locally
    * the directory with the images is printed out right above the
      pytest summary, hopefully that is a clear enough reference to the
      tests and that has the full path to the tests, not just the name
    * if people run multiple test runs and want to find older images
      they will have to know, or guess, how the pytest temp dir naming
      scheme works, or go back in their terminal scrollback
* when downloading images as artifacts to debug tests
    * The zip files with images from a job currently have names like
      end2end-screenshots-2024-08-18-fef13d4-py310-pyqt65-ubuntu-22.04.zip
    * Hopefully that zip file name is specific enough
    * I'm not sure if the individual filenames with just test name in
      them are specific enough for this case. But presumably people will
      be looking at the run logs in CI anywhere and will be able to
      match up a failing test with the screenshot easy enough

Pytest appears to sanitize test names enough for upload-artifact.
Couldn't see any docs on it, but I put all the characters it complains
about in a BDD test name and they all go stripped out.
This commit is contained in:
toofar 2024-08-24 13:11:55 +12:00
parent 622b98df12
commit ea5d15ad2e
1 changed files with 1 additions and 10 deletions

View File

@ -943,16 +943,7 @@ def take_x11_screenshot(request, screenshot_dir, record_property, xvfb):
return
img = grab(xdisplay=f":{xvfb.display}")
current_test = request.node.nodeid
fname = f"{datetime.datetime.now().isoformat()}-{current_test.replace('/', '_')}.png"
# upload-artifacts says it doesn't allow these characters if it sees
# one of them.
bad_chars = '":<>|*?\r\n'
for char in bad_chars:
fname = fname.replace(char, "_")
fpath = screenshot_dir / fname
fpath = screenshot_dir / f"{request.node.name}.png"
img.save(fpath)
record_property("screenshot", str(fpath))