Skip to content

Commit

Permalink
- fixed argv[0] not being passed as a str when executing a script;
Browse files Browse the repository at this point in the history
  • Loading branch information
jaltmayerpizzorno committed Apr 8, 2024
1 parent 7d026f4 commit b514190
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/slipcover/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_importer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
import slipcover.importer as im
from pathlib import Path
import subprocess

import sys

Expand Down Expand Up @@ -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)

0 comments on commit b514190

Please sign in to comment.