-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure that 'tox -erust' fails on bad RC. (#13753)
* Make sure that 'tox -erust' fails on bad RC. Previously, a non-zero exit code from the subprocess would not fail the tox run like we'd expect. * Use script to run cargo test, simplify subprocess call. * Use PYTHONPATH instead of PYTHONUSERBASE. This fixes an issue where the site-packages added to sys.path could be wrong (e.g. if using Framework-based Python on macOS). This was happening because the venv would install qiskit using one pathing scheme while the Python interpreter baked into the test executable would use (potentially) another when generating the path from PYTHONUSERBASE. See https://docs.python.org/3/library/sysconfig.html#installation-paths for details. To resolve this, we just set the path to the venv's site-packages via PYTHONPATH. * Add CWD to search path when running run_cargo_test.py * Update docs.
- Loading branch information
1 parent
104aaca
commit 8095ace
Showing
4 changed files
with
50 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2025. | ||
# | ||
# This code is licensed under the Apache License, Version 2.0. You may | ||
# obtain a copy of this license in the LICENSE.txt file in the root directory | ||
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Any modifications or derivative works of this code must retain this | ||
# copyright notice, and modified files need to carry a notice indicating | ||
# that they have been altered from the originals. | ||
|
||
""" | ||
Utility script to invoke cargo test within the current Python environment. | ||
Notably, this sets up the environment variables necessary for Qiskit to be | ||
found by PyO3 / our Rust test executable. | ||
""" | ||
|
||
import os | ||
import subprocess | ||
import site | ||
import sysconfig | ||
|
||
# This allows the Python interpreter baked into our test executable to find the | ||
# Qiskit installed in the active environment. | ||
os.environ["PYTHONPATH"] = os.pathsep.join([os.getcwd()] + site.getsitepackages()) | ||
|
||
# Uncomment to debug PyO3's build / link against Python. | ||
# os.environ["PYO3_PRINT_CONFIG"] = "1" | ||
|
||
# On Linux, the test executable's RPATH doesn't contain libpython, so we add it | ||
# to the dlopen search path here. | ||
os.environ["LD_LIBRARY_PATH"] = os.pathsep.join( | ||
filter(None, [sysconfig.get_config_var("LIBDIR"), os.getenv("LD_LIBRARY_PATH")]) | ||
) | ||
|
||
# The '--no-default-features' flag is used here to disable PyO3's | ||
# 'extension-module' when running the tests (which would otherwise cause link | ||
# errors). | ||
subprocess.run(["cargo", "test", "--no-default-features"], check=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters