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

Export the obtained file paths #182

Open
azmeuk opened this issue Jan 3, 2025 · 3 comments
Open

Export the obtained file paths #182

azmeuk opened this issue Jan 3, 2025 · 3 comments

Comments

@azmeuk
Copy link

azmeuk commented Jan 3, 2025

I am using pytest-regressions in CI workflows like GHA, mostly with pictures.
Often times, tests run well locally but fail in the CI environment, however GHA does not allow to display pictures to see what is wrong.
A solution is to use the upload-artifact action to make the faulty pictures downloadable.

Achieving this is not straightforward: the pytest output should be exported, then parsed in search of the .obtained pattern, then passed to upload-artifact.

It would be awesome if pytest-regression would implement an option to automate this in pytest.
For example, a --export-regressed-file-paths=/path/to/something.txt and write the paths inside.

What do you think?

@azmeuk
Copy link
Author

azmeuk commented Jan 4, 2025

For the record, is here how I currently achieve this:

      - name: Run unittest
        id: pytest
        shell: python
        run: |
          import os
          import subprocess
          import sys

          result = subprocess.run(['pytest'], capture_output=True, text=True)
          output = result.stdout
          print(output)
          if result.returncode > 0:
            files = [line.strip() for line in output.splitlines() if "obtained" in line and os.path.exists(line.strip())]
            if files:
              with open(os.getenv("GITHUB_OUTPUT"), "a") as fd:
                fd.write("pytest=" + "\n".join(files))

          sys.exit(result.returncode)
      - name: Upload failed image artifact
        if: failure()
        uses: actions/upload-artifact@v4
        with:
          name: failed-images
          path: |
            ${{ steps.pytest.outputs.pytest }}

@nicoddemus
Copy link
Member

nicoddemus commented Jan 6, 2025

Hi @azmeuk,

Indeed we have identified the same need as you, we just did not get around the time to do it.

One idea is to use a command-line flag as you did, but provide a path instead, where the plugin would generate the .obtained and .expected files for failed tests, along with some metadata to help map tests to files. Having a separate directory would be useful to easily create an artifact only with the failed snapshots.

We plan to work this eventually, but might take a awhile.

If you would like to contribute this, we would be happy to review it!

@azmeuk
Copy link
Author

azmeuk commented Jan 8, 2025

One idea is to use a command-line flag as you did, but provide a path instead, where the plugin would generate the .obtained and .expected files for failed tests, along with some metadata to help map tests to files.

Even better!

If you would like to contribute this, we would be happy to review it!

Unfortunately it is unlikely that I will have time to spare for this soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants