Skip to content

Commit 012b488

Browse files
committed
Update test_sysargv
Previous version didn't test correctly
1 parent ecd7e60 commit 012b488

File tree

4 files changed

+49
-7
lines changed

4 files changed

+49
-7
lines changed

src/tests/_compat.py

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
import operator
9+
import subprocess
910
import sys
1011
import types
1112

@@ -63,3 +64,11 @@
6364
map = imap
6465
range = xrange
6566
zip = izip
67+
68+
69+
def check_output(*args, **kwargs):
70+
"""Check output wrapper for PY2/PY3 compatibility"""
71+
output = subprocess.check_output(*args, **kwargs)
72+
if PY2:
73+
return output
74+
return output.decode("ascii")

src/tests/conftest.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
import sys
1010
import sysconfig
1111

12+
import pytest
1213
import clr
1314

1415
# Add path for `Python.Test`
1516
cwd = os.path.dirname(__file__)
16-
fixtures = os.path.join(cwd, 'fixtures')
17-
sys.path.append(fixtures)
17+
fixtures_path = os.path.join(cwd, "fixtures")
18+
sys.path.append(fixtures_path)
1819

1920
# Add References for tests
2021
clr.AddReference("Python.Test")
@@ -34,3 +35,14 @@ def pytest_report_header(config):
3435
header = ("Arch: {arch}, UCS: {ucs}, LIBDIR: {libdir}, "
3536
"Py_ENABLE_SHARED: {shared}".format(**locals()))
3637
return header
38+
39+
40+
@pytest.fixture()
41+
def filepath():
42+
"""Returns full filepath for file in `fixtures` directory."""
43+
44+
def make_filepath(filename):
45+
# http://stackoverflow.com/questions/18011902/parameter-to-a-fixture
46+
return os.path.join(fixtures_path, filename)
47+
48+
return make_filepath

src/tests/fixtures/argv-fixture.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""Helper script to test argv.
4+
Ensures that argv isn't modified after importing clr.
5+
For more details see GH#404 - argv not found"""
6+
7+
from __future__ import print_function
8+
9+
import sys
10+
import clr
11+
12+
print(sys.argv)

src/tests/test_sysargv.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,18 @@
44

55
import sys
66

7+
import pytest
78

8-
def test_sys_argv_state():
9-
"""Test sys.argv state doesn't change after clr import."""
10-
argv = sys.argv
11-
import clr
12-
assert argv == sys.argv
9+
from ._compat import check_output
10+
11+
12+
@pytest.mark.xfail(reason="argv being reset on import clr. See gh#404")
13+
def test_sys_argv_state(filepath):
14+
"""Test sys.argv state doesn't change after clr import.
15+
To better control the arguments being passed, test on a fresh python
16+
instance with specific arguments"""
17+
18+
script = filepath("argv-fixture.py")
19+
out = check_output([sys.executable, script, "foo", "bar"])
20+
assert "foo" in out
21+
assert "bar" in out

0 commit comments

Comments
 (0)