Skip to content

Commit 91ad208

Browse files
committed
improved TestPyQgsAppStartup
allow passing additional arguments after testfile do not wait the full timeout when the app already exited
1 parent 7840dbe commit 91ad208

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

tests/src/python/test_qgsappstartup.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import shutil
2525
import subprocess
2626
import tempfile
27+
import errno
2728

2829
from utilities import unittest, unitTestDataPath
2930

@@ -47,7 +48,7 @@ def tearDownClass(cls):
4748
# TODO: refactor parameters to **kwargs to handle all startup combinations
4849
def doTestStartup(self, option='', testDir='', testFile='',
4950
loadPlugins=False, customization=False,
50-
timeOut=15, env=None):
51+
timeOut=15, env=None, additionalArguments = []):
5152
"""Run QGIS with the given option. Wait for testFile to be created.
5253
If time runs out, fail.
5354
"""
@@ -75,19 +76,28 @@ def doTestStartup(self, option='', testDir='', testFile='',
7576
myenv.update(env)
7677

7778
p = subprocess.Popen(
78-
[QGIS_BIN, "--nologo", plugins, customize, option, testDir],
79+
[QGIS_BIN, "--nologo", plugins, customize, option, testDir] + additionalArguments,
7980
env=myenv)
8081

8182
s = 0
8283
ok = True
8384
while not os.path.exists(myTestFile):
85+
p.poll()
86+
if p.returncode is not None:
87+
ok = False
88+
break
8489
time.sleep(1)
8590
s += 1
8691
if s > timeOut:
8792
ok = False
8893
break
8994

90-
p.terminate()
95+
try:
96+
p.terminate()
97+
except OSError as e:
98+
if e.errno != errno.ESRCH:
99+
raise
100+
91101
return ok
92102

93103
def testOptionsPath(self):

0 commit comments

Comments
 (0)