Skip to content

Conversation

@SmithChart
Copy link
Member

@SmithChart SmithChart commented Oct 24, 2025

In some situations, when examine failed tests it would be helpful to
collect some extra information on the system state.

This changeset adds a fixture that triggers data collection.
A fixture, contrary to a hook, allows to re-use existing
fixtures (e.g. the strategy-fixture).
Using autouse=True this fixture is injected into every test.

To make the test result available in fixtures a hook in
pytest_runtest_makereport is used.

The actual diagnosis data is collected inside the strategy.
This way the infrastructure is re-useable and knowledge on the system
state stays inside the strategy.

In case of a test failure this generates log output that may look like
this:

========== FAILURES ==========
____ test_tacd_uart_3v3 ______

(...)
    @pytest.mark.lg_feature("eet")
    def test_tacd_uart_3v3(strategy, shell, eet, record_property):
(...)
>       assert True == False
E       assert True == False

tests/test_tacd.py:248: AssertionError

---- Captured log teardown -----
(...)
WARNING     post-mortem:  POST-MORTEM INFO: status
WARNING     post-mortem:  | shell
WARNING     post-mortem:  POST-MORTEM INFO: uname -a
WARNING     post-mortem:  | Linux lxatac-00034 6.17.0-20251007-1 https://github.com/linux-automation/labgrid-lxatac/pull/1 SMP PREEMPT Sun Sep 28 21:39:22 UTC 2025 armv7l GNU/Linux
WARNING     post-mortem:  POST-MORTEM INFO: cat /etc/os-release
WARNING     post-mortem:  | ID=tacos
WARNING     post-mortem:  | NAME="TAC OS - The LXA TAC operating system"
WARNING     post-mortem:  | VERSION="25.09+dev (tacos-walnascar)"
WARNING     post-mortem:  | VERSION_ID=25.09-dev
WARNING     post-mortem:  | VERSION_CODENAME="tacos-walnascar"
WARNING     post-mortem:  | PRETTY_NAME="TAC OS - The LXA TAC operating system 25.09+dev (tacos-walnascar)"
WARNING     post-mortem:  | CPE_NAME="cpe:/o:openembedded:tacos:25.09+dev"
WARNING     post-mortem:  POST-MORTEM INFO: cat /etc/buildinfo
WARNING     post-mortem:  | -----------------------
WARNING     post-mortem:  | Build Configuration:  |
WARNING     post-mortem:  | -----------------------
WARNING     post-mortem:  | DISTRO = tacos
WARNING     post-mortem:  | DISTRO_VERSION = 25.09+dev
WARNING     post-mortem:  | -----------------------
WARNING     post-mortem:  | Layer Revisions:      |
WARNING     post-mortem:  | -----------------------
WARNING     post-mortem:  | meta              = HEAD:d0b46a6624ec9c61c47270745dd0b2d5abbe6ac1
WARNING     post-mortem:  | meta-poky         = HEAD:d0b46a6624ec9c61c47270745dd0b2d5abbe6ac1
WARNING     post-mortem:  | meta-arm          = HEAD:21894cc2ea3197e6bfc1a56d889f757a09dc8b31
WARNING     post-mortem:  | meta-arm-toolchain = HEAD:21894cc2ea3197e6bfc1a56d889f757a09dc8b31
WARNING     post-mortem:  | meta-ptx          = HEAD:23e46e92946ca0a1b1da4cf3ad212169d46b0af8
WARNING     post-mortem:  | meta-oe           = HEAD:80ab58cc404959ae2f0e8b2e68935b3bfd8e8cfe
WARNING     post-mortem:  | meta-python       = HEAD:80ab58cc404959ae2f0e8b2e68935b3bfd8e8cfe
WARNING     post-mortem:  | meta-filesystems  = HEAD:80ab58cc404959ae2f0e8b2e68935b3bfd8e8cfe
WARNING     post-mortem:  | meta-networking   = HEAD:80ab58cc404959ae2f0e8b2e68935b3bfd8e8cfe
WARNING     post-mortem:  | meta-lxatac-bsp   = HEAD:44e447b099a268f87a305915a386568e0ff72b6a
WARNING     post-mortem:  | meta-lxatac-software = HEAD:44e447b099a268f87a305915a386568e0ff72b6a
WARNING     post-mortem:  | meta-labgrid      = HEAD:fa2c78d1fc3ff9519ddd14168807519ec0b6d9ee
WARNING     post-mortem:  | meta-rauc         = HEAD:a0b83842d131093e89fa4fefaaa1997f05afdf62
WARNING     post-mortem:  | meta-virtualization = HEAD:4fedb61ebf60745a367d857af255006bd3509a39
WARNING     post-mortem:  | meta-selinux      = HEAD:7ba3272c1f23266a1822442d640a40b6b4feff8c
(...)

@SmithChart SmithChart self-assigned this Oct 24, 2025
@SmithChart SmithChart marked this pull request as draft October 24, 2025 12:59
@SmithChart SmithChart marked this pull request as ready for review October 28, 2025 10:56
@SmithChart SmithChart requested a review from hnez October 28, 2025 10:56
Copy link
Member

@hnez hnez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is great. Sometimes it is quite tricky to reproduce a specific failure. Collecting as much information as possible should help us with that.

I have two suggestions you could look into, if you like. But I would also be fine with merging it as-is.

In some situations, when examine failed tests it would be helpful to
collect some extra information on the system state.

This changeset adds a fixture that triggers data collection.
A fixture, contrary to a hook, allows to re-use existing
fixtures (e.g. the `strategy`-fixture).
Using `autouse=True` this fixture is injected into every test.

To make the test result available in fixtures a hook in
`pytest_runtest_makereport` is used.

The actual diagnosis data is collected inside the strategy.
This way the infrastructure is re-useable and knowledge on the system
state stays inside the strategy.

In case of a test failure this generates log output that may look like
this:

---- 8< ----

========== FAILURES ==========
____ test_tacd_uart_3v3 ______

(...)
    @pytest.mark.lg_feature("eet")
    def test_tacd_uart_3v3(strategy, shell, eet, record_property):
(...)
>       assert True == False
E       assert True == False

tests/test_tacd.py:248: AssertionError

---- Captured log teardown -----
(...)
WARNING     post-mortem:  POST-MORTEM INFO: status
WARNING     post-mortem:  | shell
WARNING     post-mortem:  POST-MORTEM INFO: uname -a
WARNING     post-mortem:  | Linux lxatac-00034 6.17.0-20251007-1 linux-automation#1 SMP PREEMPT Sun Sep 28 21:39:22 UTC 2025 armv7l GNU/Linux
WARNING     post-mortem:  POST-MORTEM INFO: cat /etc/os-release
WARNING     post-mortem:  | ID=tacos
WARNING     post-mortem:  | NAME="TAC OS - The LXA TAC operating system"
WARNING     post-mortem:  | VERSION="25.09+dev (tacos-walnascar)"
WARNING     post-mortem:  | VERSION_ID=25.09-dev
WARNING     post-mortem:  | VERSION_CODENAME="tacos-walnascar"
WARNING     post-mortem:  | PRETTY_NAME="TAC OS - The LXA TAC operating system 25.09+dev (tacos-walnascar)"
WARNING     post-mortem:  | CPE_NAME="cpe:/o:openembedded:tacos:25.09+dev"
WARNING     post-mortem:  POST-MORTEM INFO: cat /etc/buildinfo
WARNING     post-mortem:  | -----------------------
WARNING     post-mortem:  | Build Configuration:  |
WARNING     post-mortem:  | -----------------------
WARNING     post-mortem:  | DISTRO = tacos
WARNING     post-mortem:  | DISTRO_VERSION = 25.09+dev
WARNING     post-mortem:  | -----------------------
WARNING     post-mortem:  | Layer Revisions:      |
WARNING     post-mortem:  | -----------------------
WARNING     post-mortem:  | meta              = HEAD:d0b46a6624ec9c61c47270745dd0b2d5abbe6ac1
WARNING     post-mortem:  | meta-poky         = HEAD:d0b46a6624ec9c61c47270745dd0b2d5abbe6ac1
WARNING     post-mortem:  | meta-arm          = HEAD:21894cc2ea3197e6bfc1a56d889f757a09dc8b31
WARNING     post-mortem:  | meta-arm-toolchain = HEAD:21894cc2ea3197e6bfc1a56d889f757a09dc8b31
WARNING     post-mortem:  | meta-ptx          = HEAD:23e46e92946ca0a1b1da4cf3ad212169d46b0af8
WARNING     post-mortem:  | meta-oe           = HEAD:80ab58cc404959ae2f0e8b2e68935b3bfd8e8cfe
WARNING     post-mortem:  | meta-python       = HEAD:80ab58cc404959ae2f0e8b2e68935b3bfd8e8cfe
WARNING     post-mortem:  | meta-filesystems  = HEAD:80ab58cc404959ae2f0e8b2e68935b3bfd8e8cfe
WARNING     post-mortem:  | meta-networking   = HEAD:80ab58cc404959ae2f0e8b2e68935b3bfd8e8cfe
WARNING     post-mortem:  | meta-lxatac-bsp   = HEAD:44e447b099a268f87a305915a386568e0ff72b6a
WARNING     post-mortem:  | meta-lxatac-software = HEAD:44e447b099a268f87a305915a386568e0ff72b6a
WARNING     post-mortem:  | meta-labgrid      = HEAD:fa2c78d1fc3ff9519ddd14168807519ec0b6d9ee
WARNING     post-mortem:  | meta-rauc         = HEAD:a0b83842d131093e89fa4fefaaa1997f05afdf62
WARNING     post-mortem:  | meta-virtualization = HEAD:4fedb61ebf60745a367d857af255006bd3509a39
WARNING     post-mortem:  | meta-selinux      = HEAD:7ba3272c1f23266a1822442d640a40b6b4feff8c
(...)

---- 8< ----

Signed-off-by: Chris Fiege <[email protected]>
This test depends on the DUT being in the `shell` status.
Thus it needs to depend on the appropriate fixture.

Signed-off-by: Chris Fiege <[email protected]>
Copy link
Member

@hnez hnez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool feature

@SmithChart SmithChart merged commit ac7fabf into linux-automation:master Nov 3, 2025
2 checks passed
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

Successfully merging this pull request may close these issues.

2 participants