Skip to content

Commit be935b0

Browse files
committed
Improve test marking
1 parent 8a14cc5 commit be935b0

6 files changed

Lines changed: 26 additions & 8 deletions

File tree

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,4 @@ jobs:
125125
run: py -${{ matrix.python-version}}-${{ matrix.python-bitness-to-test}} -c "import windows; print(windows)"
126126

127127
- name: Arm64 pytests
128-
run: py -${{ matrix.python-version}}-${{ matrix.python-bitness-to-test}} -m pytest tests -k "not test_debugger" -v -s
128+
run: py -${{ matrix.python-version}}-${{ matrix.python-bitness-to-test}} -m pytest tests -k "not test_debugger" -v -s -r fEsx

tests/conftest.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,9 @@ def pytest_configure(config):
159159
@pytest.hookimpl(hookwrapper=True, trylast=True)
160160
def pytest_runtest_makereport(item, call):
161161
outcome = yield
162-
# print("Make report {0} | {1}".format(item, call))
163162
if call.when == "teardown" and call.excinfo and type(call.excinfo.value) == NoLeakAssert:
164163
x = outcome.get_result()
165164
x.outcome = "failed"
166-
# import pdb;pdb.set_trace()
167165
x.LEAK = call.excinfo.value.args[0]
168166

169167

tests/pfwtest.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,24 @@ def check_injected_python_installed(request):
7373
proc = request.getfixturevalue(procparam)
7474
if not windows.injection.find_python_dll_to_inject(proc.bitness):
7575
pytest.skip("Python {0}b not installed -> skipping test with python injection into {0}b process".format(proc.bitness))
76+
return None
77+
78+
@pytest.fixture
79+
def check_dll_injection_target_architecture(request):
80+
# Find the process parameter
81+
procparams = [argname for argname in request.fixturenames if argname.startswith("proc")]
82+
if len(procparams) != 1:
83+
raise ValueError("Could not find the fixture name of the injected python")
84+
procparam = procparams[0]
85+
proc = request.getfixturevalue(procparam)
7686
# xfail ARM64 injection as its not implemented
7787
if proc.architecture == gdef.IMAGE_FILE_MACHINE_ARM64:
7888
request.applymarker("xfail")
79-
return None
8089

8190

82-
python_injection = pytest.mark.usefixtures("check_injected_python_installed")
91+
92+
dll_injection = pytest.mark.usefixtures("check_dll_injection_target_architecture")
93+
python_injection = pytest.mark.usefixtures("check_dll_injection_target_architecture", "check_injected_python_installed")
8394

8495

8596
## P2 VS PY3

tests/test_handle.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import windows
22
import windows.pipe
33

4+
from .pfwtest import *
5+
46
def test_handle_process_id():
57
handle_with_process = [h for h in windows.system.handles if h.dwProcessId]
68
handle = handle_with_process[-1]
@@ -19,8 +21,8 @@ def test_local_handle_type():
1921
PIPE_NAME = "PFW_Test_handle_Pipe"
2022
TEST_FILE_FOR_HANDLE = r"C:\Windows\explorer.exe"
2123

24+
@python_injection
2225
def test_remote_handle_type_and_name(proc32_64):
23-
# tmpfile
2426
proc32_64.execute_python("import windows; import windows.pipe")
2527
# A filename that a normal process should not have a handle on (to be sur)
2628
proc32_64.execute_python(r"""f = open(r"{filename}")""".format(filename=TEST_FILE_FOR_HANDLE))

tests/test_injection.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import windows.generated_def as gdef
1111

1212
from .conftest import pop_proc_32, pop_proc_64
13-
from .pfwtest import DEFAULT_CREATION_FLAGS
13+
from .pfwtest import DEFAULT_CREATION_FLAGS, dll_injection
1414

1515
@pytest.fixture(params=
1616
[(pop_proc_32, DEFAULT_CREATION_FLAGS),
@@ -34,17 +34,20 @@ def proc_3264_runsus(request):
3434
del proc
3535

3636
# Its really the same test as test_process.test_load_library but with suspended process as well
37+
@dll_injection
3738
def test_dll_injection(proc_3264_runsus):
3839
assert (not proc_3264_runsus.peb.Ldr) or ("wintrust.dll" not in [mod.name for mod in proc_3264_runsus.peb.modules])
3940
modaddr = windows.injection.load_dll_in_remote_process(proc_3264_runsus, "wintrust.dll")
4041
wintrustmod = [mod for mod in proc_3264_runsus.peb.modules if mod.name == "wintrust.dll"][0]
4142
assert wintrustmod.baseaddr == modaddr
4243

44+
@dll_injection
4345
def test_dll_injection_error_reporting(proc_3264_runsus):
4446
with pytest.raises(windows.injection.InjectionFailedError) as excinfo:
4547
windows.injection.load_dll_in_remote_process(proc_3264_runsus, "NO_A_DLL.dll")
4648
assert excinfo.value.__cause__.winerror == gdef.ERROR_MOD_NOT_FOUND
4749

50+
@dll_injection
4851
def test_dll_injection_access_denied(proc_3264_runsus, tmpdir):
4952
"""Emulate injection of MsStore python, were its DLL are not executable by any other append
5053
See: https://github.com/hakril/PythonForWindows/issues/72

tests/test_process.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ def test_execute_python(self, proc32_64):
214214
dword = proc32_64.read_dword(addr)
215215
assert dword == 0x42424242
216216

217+
@python_injection
217218
def test_execute_python_good_version(self, proc32_64):
218219
PIPE_NAME = "PFW_TEST_Pipe"
219220
rcode = r"""import sys; import windows; import windows.pipe; windows.pipe.send_object("{pipe}", list(sys.version_info))"""
@@ -293,6 +294,7 @@ def test_execute_python_raises(self, proc32_64):
293294
# Check the RemotePythonError contains the remote exception text
294295
assert b"ValueError: EXCEPTION_MESSAGE" in ar.value.args[0]
295296

297+
@python_injection
296298
def test_execute_python_create_console(self, proc32_64):
297299
res = proc32_64.execute_python("import windows; windows.utils.create_console()")
298300

@@ -370,17 +372,19 @@ def test_set_thread_context_64(self, proc64):
370372
time.sleep(0.1)
371373
assert t.exit_code == 0x11223344
372374

373-
375+
@dll_injection
374376
def test_load_library(self, proc32_64):
375377
DLL = "wintrust.dll"
376378
proc32_64.load_library(DLL)
377379
assert DLL in [m.name for m in proc32_64.peb.modules]
378380

381+
@dll_injection
379382
def test_load_library_suspended(self, proc32_64_suspended):
380383
DLL = "wintrust.dll"
381384
proc32_64_suspended.load_library(DLL)
382385
assert DLL in [m.name for m in proc32_64_suspended.peb.modules]
383386

387+
@dll_injection
384388
def test_load_library_unicode_name(self, proc32_64, tmpdir):
385389
mybitness = windows.current_process.bitness
386390
UNICODE_FILENAME = u'\u4e2d\u56fd\u94f6\u884c\u7f51\u94f6\u52a9\u624b.dll'

0 commit comments

Comments
 (0)