Skip to content

Commit 5a1ae93

Browse files
authored
Merge pull request #455 from NativeScript/fix-fail-test-detection
fix: failing test detection
2 parents 0a17992 + edbfad0 commit 5a1ae93

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

Diff for: core/base_test/tns_test.py

+16-12
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from products.nativescript.tns import Tns
1818

1919

20-
# noinspection PyBroadException
20+
# noinspection PyBroadException,PyUnresolvedReferences
2121
class TnsTest(unittest.TestCase):
2222
@classmethod
2323
def setUpClass(cls):
@@ -72,20 +72,21 @@ def tearDown(self):
7272
Gradle.kill()
7373
Process.kill_all_in_context()
7474
TnsTest.restore_files()
75-
# Analise test result
76-
if Settings.PYTHON_VERSION < 3:
77-
# noinspection PyUnresolvedReferences
78-
result = self._resultForDoCleanups
79-
else:
80-
# noinspection PyUnresolvedReferences
81-
result = self._outcome.result
8275

83-
outcome = 'FAILED'
84-
if result.errors == [] and result.failures == []:
85-
outcome = 'PASSED'
86-
else:
76+
# Get outcome
77+
if hasattr(self, '_outcome'): # Python 3.4+
78+
result = self.defaultTestResult() # these 2 methods have no side effects
79+
self._feedErrorsToResult(result, self._outcome.errors)
80+
else: # Python 3.2 - 3.3 or 3.0 - 3.1 and 2.7
81+
result = getattr(self, '_outcomeForDoCleanups', self._resultForDoCleanups)
82+
83+
# Take screen on test fail
84+
if result.errors or result.failures:
8785
self.get_screenshots()
8886
self.archive_apps()
87+
outcome = 'FAILED'
88+
else:
89+
outcome = 'PASSED'
8990
Log.test_end(test_name=TestContext.TEST_NAME, outcome=outcome)
9091

9192
@classmethod
@@ -113,7 +114,10 @@ def get_screenshots():
113114
try:
114115
import pyautogui
115116
png_path = os.path.join(base_path, 'host.png')
117+
File.delete(png_path)
118+
Folder.create(folder=os.path.dirname(png_path))
116119
pyautogui.screenshot().save(png_path)
120+
Log.info("Saved host os screen at {0}".format(png_path))
117121
except Exception:
118122
Log.warning('Failed to take screenshot of host os.')
119123

0 commit comments

Comments
 (0)