Skip to content

CI: log platform info in pytest - #15256

Closed
dfandrich wants to merge 4 commits into
masterfrom
dfandrich/pytestinfo
Closed

dfandrich wants to merge 4 commits into
masterfrom
dfandrich/pytestinfo

Conversation

@dfandrich

Copy link
Copy Markdown
Contributor

Use the pytest-astropy-header package to log information about the
running platform in pytest invocations so Test Clutch can include it in
the test run metadata. This also logs some things less relevant to
curl, but it's small and simple and provides the information we want and
since it's only running in the CI build it won't generally be seen by
humans.

Closes #15256

Use the pytest-astropy-header package to log information about the
running platform in pytest invocations so Test Clutch can include it in
the test run metadata.  This also logs some things less relevant to
curl, but it's small and simple and provides the information we want and
since it's only running in the CI build it won't generally be seen by
humans.

Closes #15256
@github-actions github-actions Bot added tests CI Continuous Integration labels Oct 10, 2024
@vszakats

Copy link
Copy Markdown
Member

Would it make sense to dump the same buildinfo.txt we already dump for runtests?
This would not need a new dependency, just finding a place where to print it from pytest.

@dfandrich

Copy link
Copy Markdown
Contributor Author

That would be better, but it means writing our own pytest plug-in somehow. This solution uses existing tools, but doesn't give as much information.

@vszakats

Copy link
Copy Markdown
Member

I tried doing this a little while ago, but did not look trivial indeed for some reason.

But, since then, pytests got hooked up into the build systems and started from
there, so perhaps we could dump buildinfo.txt from cmake/autotools directly?

@dfandrich

Copy link
Copy Markdown
Contributor Author

That would work, but the result would be outside what pytest logs so Test Clutch would currently ignore it. Since pytest is a standard log format that's widely used, I'm trying to avoid adding curl-specific code in there, so doing it within pytest would be much better from that perspective.

@dfandrich

Copy link
Copy Markdown
Contributor Author

Since this improves the metadata situation today, I'll submit it. If someone figures out a clean way to get more environment info into the logs, we can always switch later.

@vszakats

vszakats commented Oct 12, 2024 •

Copy link
Copy Markdown
Member

Is there any reason why a cat buildinfo.txt wouldn't work from the pytest CI step instead?

It would add the same metadata in the logs as TestClutch is already parsing for runtests.

(If it works, it can be moved inside the build scripts.)

@dfandrich

Copy link
Copy Markdown
Contributor Author

See my "That would work" comment.

@vszakats

Copy link
Copy Markdown
Member

See my "That would work" comment.

Am I understanding correctly that TestClutch is looking for the pytest log output headers to recognize where the step begins?

Would TestClutch find the buildinfo if the cat would be at the end of the step, after pytest finished?

@dfandrich

dfandrich commented Oct 12, 2024 via email

Copy link
Copy Markdown
Contributor Author

@vszakats

Copy link
Copy Markdown
Member

It ignores everything outside the pytest log, so once the log ends, it considers its job done and stops looking for more. It could be changed, of course, but when parsing arbitrary logs I want it to be conservative to avoid false triggering, especially since these log formats aren't designed to be machine readable.

Got it. Pytest already puts out there some custom output
via pytest_report_header, with server versions, etc. Would
it work to read buildinfo.txt there and add it to the string
returned from it?

@vszakats

Copy link
Copy Markdown
Member

Something like?:

--- a/tests/http/conftest.py
+++ b/tests/http/conftest.py
@@ -53,7 +53,10 @@ def pytest_report_header(config):
         report.extend([
             f'  VsFTPD: {env.vsftpd_version()}, ftp:{env.ftp_port}, ftps:{env.ftps_port}'
         ])
-    return '\n'.join(report)
+    out = '\n'.join(report)
+    with open(os.path.join(env.build_dir, 'buildinfo.txt'), 'r') as file_in:
+        out += '\n' + file_in.read()
+    return out
 
 # TODO: remove this and repeat argument everywhere, pytest-repeat can be used to repeat tests
 def pytest_generate_tests(metafunc):

Needs #15257, and untested.

@vszakats

Copy link
Copy Markdown
Member

Can confirm that after PR #15257, and this patch:

--- a/tests/http/conftest.py
+++ b/tests/http/conftest.py
@@ -53,7 +53,10 @@ def pytest_report_header(config):
         report.extend([
             f'  VsFTPD: {env.vsftpd_version()}, ftp:{env.ftp_port}, ftps:{env.ftps_port}'
         ])
-    return '\n'.join(report)
+    out = '\n'.join(report)
+    with open(os.path.join(env.build_dir, 'buildinfo.txt'), 'r') as file_in:
+        out += '\n' + file_in.read()
+    return out
 
 # TODO: remove this and repeat argument everywhere, pytest-repeat can be used to repeat tests
 def pytest_generate_tests(metafunc):

buildinfo.txt is correctly logged as part of the pytest custom info header:

============================= test session starts ==============================
platform linux -- Python 3.10.12, pytest-8.3.3, pluggy-1.5.0 -- /usr/bin/python3
cachedir: .pytest_cache
Testing curl 8.11.0-DEV
  httpd: 2.4.52, http:42605 https:51967
  httpd-proxy: 2.4.52, http:46473 https:58963
  VsFTPD: unknown, ftp:36469, ftps:40551
# This is a generated file.  Do not edit.
buildinfo.configure.tool: configure
buildinfo.configure.args:  '--disable-dependency-tracking' '--enable-unity' '--enable-test-bundles' '--enable-warnings' '--enable-werror' 'LDFLAGS=-Wl,-rpath,/home/runner/bearssl/lib' '--with-bearssl=/home/runner/bearssl' '--enable-debug'
buildinfo.host: x86_64-pc-linux-gnu
buildinfo.host.cpu: x86_64
buildinfo.host.os: linux-gnu
buildinfo.target: x86_64-pc-linux-gnu
buildinfo.target.cpu: x86_64
buildinfo.target.os: linux-gnu
buildinfo.target.flags: UNIX GCC
buildinfo.compiler: GNU_C
buildinfo.compiler.version: 11
buildinfo.sysroot: 

rootdir: /home/runner/work/curl/curl/tests
collecting ... collected 640 items

https://github.com/curl/curl/actions/runs/11305837851/job/31445757150?pr=15273#step:47:67

Would this be a solution?

@vszakats

Copy link
Copy Markdown
Member

Made a PR with the above → #15279.

vszakats added a commit that referenced this pull request Oct 13, 2024
If present.

It aims to provide TextClutch the same build information that
`runtests.pl` already is providing.

Ref: https://testclutch.curl.se/static/reports/feature-matrix.html
Ref: #15256
Follow-up to 1fdea16 #14802
Closes #15279
@dfandrich

Copy link
Copy Markdown
Contributor Author

This is now obsolete since the information is now available from our pytest harness directly: #15470

@dfandrich dfandrich closed this Nov 4, 2024
@dfandrich
dfandrich deleted the dfandrich/pytestinfo branch November 4, 2024 16:54
pps83 pushed a commit to pps83/curl that referenced this pull request Apr 26, 2025
If present.

It aims to provide TextClutch the same build information that
`runtests.pl` already is providing.

Ref: https://testclutch.curl.se/static/reports/feature-matrix.html
Ref: curl#15256
Follow-up to 1fdea16 curl#14802
Closes curl#15279
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI Continuous Integration tests

Development

Successfully merging this pull request may close these issues.

2 participants