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

tdtest tool does not take pytest args correctly after latest test refactoring in 3.1 tag #321

Open
jinengandhi-intel opened this issue Jan 28, 2025 · 1 comment

Comments

@jinengandhi-intel
Copy link

Describe the bug
In 3.1 tag a new wrapper script tdtest was introduced which is supposed to be capable of taking pytest args from command line and internally it passes to tox, but this is broken. It passes all args as 1 string. So for example if you pass the test folder along with --junit-xml they are taken as 1 string.

To Reproduce
Run the following commands with 3.1 tag.

  1. sudo ./tdtest tests/host --junit-xml=host.xml

Result: its looking for a folder with the name tests/host --junit-xml=host.xml

tdx: commands[0]> python3 -m pytest -s -v --ignore=lib/ 'tests/host --junit-xml=host.xml'
================================================================= test session starts ==================================================================
platform linux -- Python 3.12.3, pytest-8.2.1, pluggy-1.5.0 -- /home/root123/jenkins/workspace/TDX/tdx_nightly_build/ci/tdx/tests/.tox/.venv/bin/python3
cachedir: .tox/.venv/.pytest_cache
rootdir: /home/root123/jenkins/workspace/TDX/tdx_nightly_build/ci/tdx/tests
configfile: pytest.ini
collected 0 items

ERROR: file or directory not found: tests/host --junit-xml=host.xml

=================================================================== warnings summary ===================================================================
  1. sudo ./tdtest --junitxml=test_host.xml tests/host

Result: It doesn't take tests/host as the folder to run the tests and instead run all 52 tests and create random folder with the name test_host.xml tests

tdx: commands[0]> python3 -m pytest -s -v --ignore=lib/ '--junitxml=test_host.xml tests/host'
================================================================= test session starts ==================================================================
platform linux -- Python 3.12.3, pytest-8.2.1, pluggy-1.5.0 -- /home/root123/jenkins/workspace/TDX/tdx_nightly_build/ci/tdx/tests/.tox/.venv/bin/python3
cachedir: .tox/.venv/.pytest_cache
rootdir: /home/root123/jenkins/workspace/TDX/tdx_nightly_build/ci/tdx/tests
configfile: pytest.ini
collected 52 items

tests/boot/test_boot_basic.py::test_guest_boot

Expected behavior

I debugged the issue and the fix is in the tdtest wrapper script where the pytest args are wrapped in double quotes, removing this resolves the issue.

diff --git a/tests/tdtest b/tests/tdtest
index 5a1584a..d69ff87 100755
--- a/tests/tdtest
+++ b/tests/tdtest
@@ -77,4 +77,4 @@ export TDXTEST_GUEST_IMG

 echo "Run tests with TD image: ${TDXTEST_GUEST_IMG}"
 echo "  pytest args: ${pytest_args}"
-tox -- --ignore=lib/ "${pytest_args}"
+tox -- --ignore=lib/ ${pytest_args}

After the above fix things work fine:

sudo ./tdtest --junit-xml=host.xml tests/host
tdx: commands[0]> python3 -m pytest -s -v --ignore=lib/ --junit-xml=host.xml tests/host
================================================================= test session starts ==================================================================
platform linux -- Python 3.12.3, pytest-8.2.1, pluggy-1.5.0 -- /home/root123/jenkins/workspace/TDX/tdx_nightly_build/ci/tdx/tests/.tox/.venv/bin/python3
cachedir: .tox/.venv/.pytest_cache
rootdir: /home/root123/jenkins/workspace/TDX/tdx_nightly_build/ci/tdx/tests
configfile: pytest.ini
collected 4 items

tests/host/test_host_tdx_hardware.py::test_host_tdx_hardware_enabled PASSED
tests/host/test_host_tdx_software.py::test_host_tdx_cpu PASSED
tests/host/test_host_tdx_software.py::test_host_tdx_software Y
Y
PASSED
tests/host/test_host_tdx_software.py::test_host_tdx_module_load PASSED

System report
Please run the system-report.sh script (located in the root directory of this repo) on your host system and copy the output below.

Copy link

Thank you for reporting your feedback to us!

The internal ticket has been created: https://warthogs.atlassian.net/browse/PEK-1618.

This message was autogenerated

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

1 participant