Merge lp:~sbaldassin/ubuntu-system-tests/close_apps into lp:ubuntu-system-tests

Proposed by Santiago Baldassin
Status: Rejected
Rejected by: Santiago Baldassin
Proposed branch: lp:~sbaldassin/ubuntu-system-tests/close_apps
Merge into: lp:ubuntu-system-tests
Diff against target: 126 lines (+16/-26)
4 files modified
ubuntu_system_tests/helpers/autopilot/__init__.py (+2/-17)
ubuntu_system_tests/helpers/context.py (+7/-1)
ubuntu_system_tests/tests/base.py (+5/-8)
ubuntu_system_tests/tests/test_calculator.py (+2/-0)
To merge this branch: bzr merge lp:~sbaldassin/ubuntu-system-tests/close_apps
Reviewer Review Type Date Requested Status
platform-qa-bot continuous-integration Approve
Sergio Cazzolato Pending
Canonical Platform QA Team Pending
Review via email: mp+294860@code.launchpad.net

Commit message

Refactor in the way the system tests uses the context and clean the created resources

Description of the change

This change includes:

Moving the shared context from a global variable shared across modules to an object that's initialized for every test class. This allows us to
   - have a context that's independent from class to class
   - change the context values depending on the test class: i.e retry_times

Remove the reference to addCleanup added in the shared context which forced us to duplicate work like cleaning the clean up queue which is already taken care in the TestCase constructor. Moreover that reference brakes the class structure by exposing a class method across python modules

Using the addCleanup method already exposed to the tests by extending from BaseUbuntuSystemTestCase. That way we keep the class definition introduced by unittests and each test can clean the created resources the way they want

Removing the cleanup from the get_proxy methods which had two issues:
if we failed to get the proxy object then the cleanup was never updated
we were manipulating the test context in a method that was just supposed to return a proxy object

To post a comment you must log in.
Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Approve (continuous-integration)

Unmerged revisions

387. By Santiago Baldassin

fixing flake 8 issue

386. By Santiago Baldassin

Moving shared context to a context that's independent for every test

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_system_tests/helpers/autopilot/__init__.py'
2--- ubuntu_system_tests/helpers/autopilot/__init__.py 2016-04-25 18:31:03 +0000
3+++ ubuntu_system_tests/helpers/autopilot/__init__.py 2016-05-17 01:57:53 +0000
4@@ -25,7 +25,6 @@
5 from autopilot import introspection
6 from autopilot.exceptions import StateNotFoundError
7
8-from ubuntu_system_tests.helpers import context
9 from ubuntu_system_tests.helpers import processes
10 from ubuntu_system_tests.helpers.timeout import timeout
11 from ubuntu_system_tests.helpers import wait_until
12@@ -237,26 +236,17 @@
13
14
15 def get_proxy_object_for_existing_app(
16- process_name, cleanup_process=None,
17+ process_name,
18 base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
19 """
20 Return proxy object from existing application process.
21
22- Add cleanup action to close the application using cleanup_process
23- parameter. If cleanup_process is None then process_name is used as the
24- cleanup target using ensure_application_closed().
25-
26- :param pname: Name of required application process.
27- :param cleanup_process: Name of process to clean up.
28+ :param process_name: Name of required application process.
29 :param base: custom emulator base for proxy object
30 :return: Proxy object for the desired application.
31
32 """
33- if not cleanup_process:
34- cleanup_process = process_name
35 proxy = get_proxy_object_for_existing_process(process_name, base)
36- context.shared.add_cleanup(processes.ensure_application_closed,
37- cleanup_process)
38 return proxy
39
40
41@@ -270,10 +260,6 @@
42 """
43 Return proxy object from existing qmlscene process.
44
45- Add cleanup action to close the application using cleanup_process
46- parameter. If cleanup_process is None then process_id is used as the
47- cleanup target using processes.stop_qmlscene_process().
48-
49 :param qmlfile: Thje name of the QML file for the required process
50 :return: Proxy object for the desired qmlscene process
51
52@@ -283,7 +269,6 @@
53 pid=process_id,
54 emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase
55 )
56- context.shared.add_cleanup(processes.stop_qmlscene_process, qmlfile)
57 return proxy
58
59
60
61=== modified file 'ubuntu_system_tests/helpers/context.py'
62--- ubuntu_system_tests/helpers/context.py 2016-02-02 20:00:15 +0000
63+++ ubuntu_system_tests/helpers/context.py 2016-05-17 01:57:53 +0000
64@@ -20,4 +20,10 @@
65
66 from ubuntu_system_tests.helpers import AttrDict
67
68-shared = AttrDict()
69+
70+class Context(object):
71+
72+ def __init__(self, timers, retry_time):
73+ self.shared = AttrDict()
74+ self.shared.timers = timers
75+ self.shared.retry_time = retry_time
76
77=== modified file 'ubuntu_system_tests/tests/base.py'
78--- ubuntu_system_tests/tests/base.py 2016-05-09 18:32:36 +0000
79+++ ubuntu_system_tests/tests/base.py 2016-05-17 01:57:53 +0000
80@@ -40,6 +40,7 @@
81 from ubuntu_system_tests.helpers import context
82 from ubuntu_system_tests.helpers import images
83 from ubuntu_system_tests.helpers import mir
84+from ubuntu_system_tests.helpers.context import Context
85 from ubuntu_system_tests.helpers.processes import wait_for_job_spawned
86 from ubuntu_system_tests.helpers import screen
87 from ubuntu_system_tests.helpers.timeout import timeout
88@@ -58,6 +59,10 @@
89
90 class BaseUbuntuSystemTestCase(testcase.AutopilotTestCase):
91
92+ def __init__(self, timers=[], retry_time=10000):
93+ self.context = Context(timers, retry_time)
94+ super()
95+
96 @classmethod
97 def setUpClass(cls):
98 unity8.ensure_unity_stopped()
99@@ -71,14 +76,6 @@
100 def setUp(self):
101 super().setUp()
102 self._reset_autopilot_registry()
103- self._init_shared_context()
104-
105- def _init_shared_context(self):
106- # The shared context is reset for each test
107- context.shared.clear()
108- context.shared.add_cleanup = self.addCleanup
109- context.shared.timers = []
110- context.shared.retry_time = 10000
111
112 def _get_unity8_proxy_object(self):
113 return autopilot.get_job_proxy_object('unity8')
114
115=== modified file 'ubuntu_system_tests/tests/test_calculator.py'
116--- ubuntu_system_tests/tests/test_calculator.py 2016-02-03 20:45:19 +0000
117+++ ubuntu_system_tests/tests/test_calculator.py 2016-05-17 01:57:53 +0000
118@@ -27,6 +27,8 @@
119 super().setUp()
120 self.unity_proxy = self.restart_unity()
121 self.calculator = calculator.launch_calculator_app()
122+ if self.calculator is not None:
123+ self.addCleanup(calculator.close_calculator_app())
124
125 def test_simple_multiplication(self):
126 """Multiply two numbers."""

Subscribers

People subscribed via source and target branches