From b51419042ca4028705e1557a08b6094feecfab8c Mon Sep 17 00:00:00 2001 From: Juan Altmayer Pizzorno Date: Sun, 7 Apr 2024 20:33:12 -0400 Subject: [PATCH] - fixed argv[0] not being passed as a str when executing a script; --- src/slipcover/__main__.py | 2 +- tests/test_importer.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/slipcover/__main__.py b/src/slipcover/__main__.py index 4ef0e80..f1533af 100644 --- a/src/slipcover/__main__.py +++ b/src/slipcover/__main__.py @@ -222,7 +222,7 @@ def printit(coverage, outfile): script_globals['__name__'] = '__main__' script_globals['__file__'] = args.script - sys.argv = [args.script, *args.script_or_module_args] + sys.argv = [str(args.script), *args.script_or_module_args] # the 1st item in sys.path is always the main script's directory sys.path.pop(0) diff --git a/tests/test_importer.py b/tests/test_importer.py index 8a9c280..bc3af3c 100644 --- a/tests/test_importer.py +++ b/tests/test_importer.py @@ -1,6 +1,7 @@ import pytest import slipcover.importer as im from pathlib import Path +import subprocess import sys @@ -276,3 +277,13 @@ def test(): p = subprocess.run([sys.executable, "-m", "slipcover", "--silent", "-m", "pytest", "-vv", cmdfile]) assert p.returncode == 0 + + +def test_run_script_argv_is_str(tmp_path): + cmdfile = tmp_path / "t.py" + cmdfile.write_text(""" +import sys +assert isinstance(sys.argv[0], str) +""") + + subprocess.run([sys.executable, "-m", "slipcover", "--silent", cmdfile], check=True)