Closed Bug 888506 Opened 11 years ago Closed 11 years ago

Unable to skip a test in setUp before calling MarionetteTestCase.setUp

Categories

(Remote Protocol :: Marionette, defect)

defect
Not set
normal

Tracking

(firefox23 wontfix, firefox24 wontfix, firefox25 fixed, b2g18 fixed, b2g18-v1.0.0 wontfix, b2g18-v1.0.1 wontfix, b2g-v1.1hd fixed)

RESOLVED FIXED
mozilla25
Tracking Status
firefox23 --- wontfix
firefox24 --- wontfix
firefox25 --- fixed
b2g18 --- fixed
b2g18-v1.0.0 --- wontfix
b2g18-v1.0.1 --- wontfix
b2g-v1.1hd --- fixed

People

(Reporter: davehunt, Assigned: mbu)

References

Details

Attachments

(1 file)

In some tests we would like to skip when certain prerequisites are not met, such as certain test variables. It would be ideal to do this before even setting up a Marionette session or some other expensive setUp operations, however with the recent changes from bug 874599 and bug 886741 this is no longer possible.

If I have a setUp method such as:

def setUp(self):
    try:
        self.testvars['email']['ActiveSync']
    except KeyError:
        raise SkipTest('account details not present in test variables')
    GaiaTestCase.setUp(self)

I get the following traceback:

Traceback (most recent call last):
  File "/Users/dhunt/.virtualenvs/gaia-ui-tests/bin/gaiatest", line 8, in <module>
    load_entry_point('gaiatest==0.12', 'console_scripts', 'gaiatest')()
  File "/Users/dhunt/workspace/gaia-ui-tests/gaiatest/runtests.py", line 70, in main
    cli(runner_class=GaiaTestRunner, parser_class=GaiaTestOptions)
  File "/Users/dhunt/.virtualenvs/gaia-ui-tests/lib/python2.7/site-packages/marionette/runtests.py", line 766, in cli
    runner = startTestRunner(runner_class, options, tests)
  File "/Users/dhunt/.virtualenvs/gaia-ui-tests/lib/python2.7/site-packages/marionette/runtests.py", line 758, in startTestRunner
    runner.run_tests(tests)
  File "/Users/dhunt/.virtualenvs/gaia-ui-tests/lib/python2.7/site-packages/marionette/runtests.py", line 417, in run_tests
    self.run_test(test)
  File "/Users/dhunt/.virtualenvs/gaia-ui-tests/lib/python2.7/site-packages/marionette/runtests.py", line 520, in run_test
    results = runner.run(suite)
  File "/Users/dhunt/.virtualenvs/gaia-ui-tests/lib/python2.7/site-packages/marionette/runtests.py", line 153, in run
    test(result)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/suite.py", line 70, in __call__
    return self.run(*args, **kwds)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/suite.py", line 108, in run
    test(result)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/case.py", line 395, in __call__
    return self.run(*args, **kwds)
  File "/Users/dhunt/.virtualenvs/gaia-ui-tests/lib/python2.7/site-packages/marionette/marionette_test.py", line 168, in run
    self.cleanTest()
  File "/Users/dhunt/.virtualenvs/gaia-ui-tests/lib/python2.7/site-packages/marionette/marionette_test.py", line 247, in cleanTest
    self._deleteSession()
  File "/Users/dhunt/.virtualenvs/gaia-ui-tests/lib/python2.7/site-packages/marionette/marionette_test.py", line 250, in _deleteSession
    self.duration = time.time() - self.start_time
AttributeError: 'TestSendActiveSyncEmail' object has no attribute 'start_time'

In this case duration should be 0 as the test is skipped. If I put the raise SkipTest after the setUp method I get no traceback.
We should check that the start_time attribute exists before attempting to use it.
Assignee: nobody → mat.bultel
Prevent start_time attribute error and add unit tests.
Attachment #769639 - Flags: review?(jgriffin)
Comment on attachment 769639 [details] [diff] [review]
Prevent error if object as not attribute start_time

Review of attachment 769639 [details] [diff] [review]:
-----------------------------------------------------------------

::: testing/marionette/client/marionette/marionette_test.py
@@ +247,5 @@
>          self._deleteSession()
>  
>      def _deleteSession(self):
> +        if hasattr(self, 'start_time'):
> +            self.duration = time.time() - self.start_time

This would mean duration would not be set. Could we set duration in this case to zero? Otherwise we would need to catch this in the XML/HTML reports.
Duration is set into __init__ of CommonTestCase :

    def __init__(self, methodName):
        unittest.TestCase.__init__(self, methodName)
        self.loglines = None
        self.duration = 0

So, if setUp failed, duration is still set to zero.
Ah, thanks! :)
Comment on attachment 769639 [details] [diff] [review]
Prevent error if object as not attribute start_time

Review of attachment 769639 [details] [diff] [review]:
-----------------------------------------------------------------

Thanks mbu.
Attachment #769639 - Flags: review?(jgriffin) → review+
Blocks: 889469
https://hg.mozilla.org/mozilla-central/rev/df89dc4a968d
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla25
Product: Testing → Remote Protocol
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: