Closed Bug 1595814 Opened 6 years ago Closed 5 years ago

ImportError: cannot import name '_ExpectedFailure'

Categories

(Remote Protocol :: Marionette, defect, P3)

70 Branch
defect

Tracking

(firefox78 fixed)

RESOLVED FIXED
mozilla78
Tracking Status
firefox78 --- fixed

People

(Reporter: rgpt, Assigned: bc)

References

Details

Attachments

(2 files)

User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0

Steps to reproduce:

Attempt to run marionette-test from python3

$ python3 mach marionette-test

Actual results:

ImportError: cannot import name '_ExpectedFailure'

File "/home/rgpt/Desktop/mozilla/mozilla-unified/python/mach/mach/main.py", line 360, in run
return self._run(argv)
File "/home/rgpt/Desktop/mozilla/mozilla-unified/python/mach/mach/main.py", line 415, in _run
args = parser.parse_args(argv)
File "/usr/lib/python3.5/argparse.py", line 1735, in parse_args
args, argv = self.parse_known_args(args, namespace)
File "/usr/lib/python3.5/argparse.py", line 1767, in parse_known_args
namespace, args = self._parse_known_args(args, namespace)
File "/usr/lib/python3.5/argparse.py", line 1976, in _parse_known_args
stop_index = consume_positionals(start_index)
File "/usr/lib/python3.5/argparse.py", line 1932, in consume_positionals
take_action(action, args)
File "/usr/lib/python3.5/argparse.py", line 1841, in take_action
action(self, namespace, argument_values, option_string)
File "/home/rgpt/Desktop/mozilla/mozilla-unified/python/mach/mach/dispatcher.py", line 179, in call
if handler.parser:
File "/home/rgpt/Desktop/mozilla/mozilla-unified/python/mach/mach/decorators.py", line 77, in parser
self._parser = self._parser()
File "/home/rgpt/Desktop/mozilla/mozilla-unified/testing/marionette/mach_commands.py", line 24, in create_parser_tests
from marionette_harness.runtests import MarionetteArguments
File "/home/rgpt/Desktop/mozilla/mozilla-unified/build/mach_bootstrap.py", line 431, in call
module = self._original_import(name, globals, locals, fromlist, level)
File "/home/rgpt/Desktop/mozilla/mozilla-unified/build/mach_bootstrap.py", line 431, in call
module = self._original_import(name, globals, locals, fromlist, level)
File "/home/rgpt/Desktop/mozilla/mozilla-unified/testing/marionette/harness/marionette_harness/init.py", line 9, in <module>
from .marionette_test import (
File "/home/rgpt/Desktop/mozilla/mozilla-unified/build/mach_bootstrap.py", line 431, in call
module = self._original_import(name, globals, locals, fromlist, level)
File "/home/rgpt/Desktop/mozilla/mozilla-unified/testing/marionette/harness/marionette_harness/marionette_test/init.py", line 27, in <module>
from .testcases import (
File "/home/rgpt/Desktop/mozilla/mozilla-unified/build/mach_bootstrap.py", line 431, in call
module = self._original_import(name, globals, locals, fromlist, level)
File "/home/rgpt/Desktop/mozilla/mozilla-unified/testing/marionette/harness/marionette_harness/marionette_test/testcases.py", line 17, in <module>
from unittest.case import (

Expected results:

marionette tests should have started running seamlessly.

Blocks: 1355537

Rishi, thank you for filing this issue! It is indeed a blocker for us to move Marionette over to Python3. Would you also be interested to work on this bug? If yes, what would be your first steps?

Status: UNCONFIRMED → NEW
Ever confirmed: true
Priority: -- → P3

Yes whimboo, I am interested in working on this bug. I would try make marionette harness work with py3 so as to keep it compatible with py2 so marionette test on py2 are not affected

Great. So it's reserved for you. Let me know when you need help.

Mentor: hskupin
Whiteboard: [lang=py]

Based on the search It seems _ExpectedFailure Exception Class is removed from python3 unittest . And, as it was a internal variable it was not mentioned in the py3 porting guide.

_ExpectedFailure is only being used to raise an exception and call expected_failure after catching the exception. (as mentioned in the snippet below) Which could be directly called without raising an exception. The reason we could do that is because _ExpectedFailure is not being raised from anywhere testing module, but this (testcases.py) file

Another Solution would be create our custom Exception to mimic the one python2.7 and follow the same for both py2 and py3

@whimboo what should be the preferred course of action ?

IN : mozilla-unified/testing/marionette/harness/marionette_harness/marionette_test/testcases.py

try:
                if self.expected == "fail":
                    try:
                        self.setUp()
                    except Exception:
                        raise _ExpectedFailure(sys.exc_info())
                else:
                    self.setUp()
            except SkipTest as e:
                self._addSkip(result, str(e))
            except (KeyboardInterrupt, UnresponsiveInstanceException):
                raise
            except _ExpectedFailure as e:
                expected_failure(result, e.exc_info)
            except Exception:
                self._enter_pm()
                result.addError(self, sys.exc_info())
       ```
Flags: needinfo?(hskupin)

Could you please check how _ExpectedFailure is implemented in Python2? If it's just some lines of code we could indeed just add it to our file.

Flags: needinfo?(hskupin)
Depends on: 1597687
Depends on: 1597690

Both newly filed bugs shouldn't actually block this bug from getting landed but bug 1355537 instead.

No longer depends on: 1597687, 1597690
Assignee: nobody → rishigpt2009
Status: NEW → ASSIGNED
Attachment #9109216 - Attachment description: Bug 1595814 - Making marionette harness compatible to py3 r=whimboo → Bug 1595814 : Adding Expected Failure and Unexpected Success class explicitly to throw error r=whimboo
Attachment #9109216 - Attachment description: Bug 1595814 : Adding Expected Failure and Unexpected Success class explicitly to throw error r=whimboo → Bug 1595814 - [marionette] Don't import private _ExpectedFailure and _UnexpectedSuccess classes from unittest. r=whimboo
Pushed by hskupin@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/a3b107922e81 [marionette] Don't import private _ExpectedFailure and _UnexpectedSuccess classes from unittest. r=whimboo,marionette-reviewers
Flags: needinfo?(rishigpt2009)

Rishi, it looks like this bug got under the wire and I completely missed to reply in regards of the backout. I wonder if you are still interested to work on it? Please let me know. Thanks a lot.

Flags: needinfo?(rishigpt2009)

Hm, ok. I assume not. Opening up this bug for others to pick up.

Assignee: rishigpt2009 → nobody
Status: ASSIGNED → NEW
Flags: needinfo?(rishigpt2009)

Hi i would like to work on this if its still open?

Hi rcrahul60. Thank you for your interest, but I have to admit that I missed to remove this bug from the mentored list given that it will be too hard to get fixed for someone new on the code base. We have plenty of other bugs, so maybe you can find something else?

Otherwise if you are an experienced Python developer and have knowledge with Python3 feel free to pick it up.

Thanks.

Mentor: hskupin
Whiteboard: [lang=py]
Assignee: nobody → bob
Status: NEW → ASSIGNED
Pushed by bclary@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/981d3e5d9a00 work around marionette dependency on private classes in Python2 unittest/case.py, r=whimboo,marionette-reviewers,maja_zf.
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla78
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: