check
is not recommended.120 try:
121 return importlib.import_module(library_name)
122 except ImportError:
123 completed = subprocess.run(["python3", "-m", "pip", "install", package_name])124 if completed.returncode != 0:
125 raise AssertionError(
126 f"Failed to install library {package_name} (pip exited with code {completed.returncode})"
subprocess.run
uses a default of check=False
, which means that a nonzero exit code will be
ignored by default, instead of raising an exception.
You can ignore this issue if this behaviour is intended.
# Nonzero exit code will be ignored here
subprocess.run(['notify-send', '-u', 'critical', msg])
# Exception will be raised for nonzero exit code
subprocess.run(['notify-send', '-u', 'critical', msg], check=True) # some comment