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

Provide link to failing test and line in annotations #35

Open
EnricoMi opened this issue Oct 25, 2020 · 10 comments
Open

Provide link to failing test and line in annotations #35

EnricoMi opened this issue Oct 25, 2020 · 10 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@EnricoMi
Copy link
Owner

EnricoMi commented Oct 25, 2020

Question #32 made me think of linking to the failing test and line form the annotations. Given the commit sha, test file and line, the action could generate a link like this and add to the respective annotation:

https://github.com/EnricoMi/publish-unit-test-result-action/blob/de7f7f0c5f7694846ce69e3384f2e5a03253c141/test/test_publish.py#L35

Such a link gets nicely rendered by GitHub:

self.assertEqual(get_formatted_digits(None), (3, 0))

Providing a few lines before and after gives a nice context:

def test_get_formatted_digits(self):
self.assertEqual(get_formatted_digits(None), (3, 0))
self.assertEqual(get_formatted_digits(None, 1), (3, 0))
self.assertEqual(get_formatted_digits(None, 123), (3, 0))

Let's hope that also holds for annotations. It probably won't because annotations do not support markdown.

Resolving the test file path from the test result file will be challenging. This might work best with some configuration like how many directories to remove from the path or which path to prepend.

@EnricoMi EnricoMi added enhancement New feature or request good first issue Good for newcomers labels Oct 25, 2020
@EnricoMi
Copy link
Owner Author

I see the following issues here:

  1. The correct path within the repo needs to be derived from the test result file, which might require some extra configuration
  2. This might not work for pull requests from fork repositories as the commit is part of the fork but the check run is part of the target repo. Such a link only works inside a repository.
  3. Check Run annotations object (which would be the best place to add this) does not seem to support markdown: https://docs.github.com/en/rest/reference/checks#create-a-check-run

@TWiStErRob
Copy link

I've been playing around with attributing JUnit XML to lines in a repo, I got this far:
image
If the top of the stack trace contains a filename, that can be used to identify the line:
image
but of course with real assertEquals this would be inside JUnit or AssertJ, so I agree with additional configuration, where the company package name(s) would be required. I guess where this breaks down is if a non-changed test file fails.

Note: moving from GH check annotations to Sarif uploads may be a way:
image

@EnricoMi
Copy link
Owner Author

EnricoMi commented Nov 1, 2021

I guess where this breaks down is if a non-changed test file fails

The annotations API has exactly that limitation as it only shows the annotation in the Changes tab so only modified failing tests show the annotation. The propose links (see PR description) have the advantage that they reference the commit, not the changes, so they are able to show the content no matter if tests are part of the changes.

@EnricoMi
Copy link
Owner Author

Looks like Github can show annotations done to unchanged files (Beta):
https://github.com/EnricoMi/publish-unit-test-result-action/blob/master/misc/github-pull-request-changes-annotation.png

@TWiStErRob
Copy link

TWiStErRob commented May 26, 2023

Yeah, I've seen that too! It looks amazing.

What do I need to do to get the annotations for JUnit? I don't remember seeing it for tests yet.

Edit: might be #452

@EnricoMi
Copy link
Owner Author

In general, two things are needed:

  1. the test result files have to contain the filename of the test case
  2. the path has to be relative to the git repo root

@TWiStErRob
Copy link

TWiStErRob commented May 26, 2023

JUnit XML is not famous for those attributes 😞, but I see you support some: https://github.com/EnricoMi/publish-unit-test-result-action/blob/master/python/publish/junit.py#L268-L269, where did you get those names from, because the official schema doesn't have it for Maven? Neither the Ant one. Anyway, it's good to know that if I can "enrich" the XML, it'll "just work".

@dmarkey
Copy link

dmarkey commented Sep 20, 2023

Hey, came across this issue with pytest runs in subdirectories don't have the correct annotation.. thinking of some sed magic to add the prefix so the annotations are set correctly, unless there is an alternative?

@EnricoMi
Copy link
Owner Author

@dmarkey I think #482 is what you want. Maybe I have to pick up that piece of work and do it myself.

@EnricoMi
Copy link
Owner Author

See #495 for a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants