Closed Bug 1917379 Opened 2 months ago Closed 2 months ago

SyntaxError: invalid decimal literal File "testing/marionette/mach_commands.py", line 113, in marionette_test

Categories

(Testing :: Marionette Client and Harness, defect)

defect

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: sfoster, Unassigned)

Details

Apparently my macbook (M1, Sonoma) has python 3.12 installed. When I run marionette-test e.g. ./mach marionette-test -vv testing/marionette/harness/marionette_harness/tests/unit/test_quit_restart.py, the runner starts up, opens the first browser window, then it stops with the following exception:

AttributeError: module 'unittest' has no attribute '_TextTestResult'. Did you mean: 'TextTestResult'?

  File "/Users/sfoster/mozilla-unified/testing/marionette/mach_commands.py", line 113, in marionette_test
    return run_marionette(tests, topsrcdir=command_context.topsrcdir, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sfoster/mozilla-unified/testing/marionette/mach_commands.py", line 58, in run_marionette
    failed = MarionetteHarness(MarionetteTestRunner, args=vars(args)).run()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sfoster/mozilla-unified/testing/marionette/harness/marionette_harness/runtests.py", line 79, in run
    runner.run_tests(tests)
  File "/Users/sfoster/mozilla-unified/testing/marionette/harness/marionette_harness/runner/base.py", line 1016, in run_tests
    self.run_test_sets()
  File "/Users/sfoster/mozilla-unified/testing/marionette/harness/marionette_harness/runner/base.py", line 1242, in run_test_sets
    self.run_test_set(self.tests)
  File "/Users/sfoster/mozilla-unified/testing/marionette/harness/marionette_harness/runner/base.py", line 1212, in run_test_set
    self.run_test(test["filepath"], test["expected"])
  File "/Users/sfoster/mozilla-unified/testing/marionette/harness/marionette_harness/runner/base.py", line 1176, in run_test
    results = runner.run(suite)
              ^^^^^^^^^^^^^^^^^
  File "/Users/sfoster/mozilla-unified/testing/marionette/harness/marionette_harness/runner/base.py", line 254, in run
    result = super(MarionetteTextTestRunner, self).run(test)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sfoster/mozilla-unified/testing/mozbase/moztest/moztest/adapters/unit.py", line 207, in run
    test(result)
  File "/opt/homebrew/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/suite.py", line 84, in __call__
    return self.run(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/suite.py", line 122, in run
    test(result)
  File "/opt/homebrew/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/case.py", line 690, in __call__
    return self.run(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sfoster/mozilla-unified/testing/marionette/harness/marionette_harness/marionette_test/testcases.py", line 247, in run
    result.stopTest(self)
  File "/Users/sfoster/mozilla-unified/testing/marionette/harness/marionette_harness/runner/base.py", line 225, in stopTest
    unittest._TextTestResult.stopTest(self, *args, **kwargs)
    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/__init__.py", line 85, in __getattr__
    raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

Switching to python3.11 (python3.11 ./mach marionette-test ...etc) seems to work better. The whole test completes, but winds up failing with:

SyntaxError: invalid decimal literal  File "/Users/sfoster/mozilla-unified/testing/marionette/mach_commands.py", line 113, in marionette_test
    return run_marionette(tests, topsrcdir=command_context.topsrcdir, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sfoster/mozilla-unified/testing/marionette/mach_commands.py", line 58, in run_marionette
    failed = MarionetteHarness(MarionetteTestRunner, args=vars(args)).run()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sfoster/mozilla-unified/testing/marionette/harness/marionette_harness/runtests.py", line 79, in run
    runner.run_tests(tests)
  File "/Users/sfoster/mozilla-unified/testing/marionette/harness/marionette_harness/runner/base.py", line 1016, in run_tests
    self.run_test_sets()
  File "/Users/sfoster/mozilla-unified/testing/marionette/harness/marionette_harness/runner/base.py", line 1242, in run_test_sets
    self.run_test_set(self.tests)
  File "/Users/sfoster/mozilla-unified/testing/marionette/harness/marionette_harness/runner/base.py", line 1212, in run_test_set
    self.run_test(test["filepath"], test["expected"])
  File "/Users/sfoster/mozilla-unified/testing/marionette/harness/marionette_harness/runner/base.py", line 1156, in run_test
    handler.add_tests_to_suite(
  File "/Users/sfoster/mozilla-unified/testing/marionette/harness/marionette_harness/marionette_test/testcases.py", line 380, in add_tests_to_suite
    test_mod = load_source(mod_name, filepath)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sfoster/mozilla-unified/testing/mozbase/mozfile/mozfile/mozfile.py", line 649, in load_source
    loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 936, in exec_module
  File "<frozen importlib._bootstrap_external>", line 1074, in get_code
  File "<frozen importlib._bootstrap_external>", line 1004, in source_to_code
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed

The TextTestResult class was officially added in Python 3.2, and it looks like it got as well removed with Python 3.12. So we should clearly not use the internal name anymore.

There is actually already a patch added for bug 1917556 which will fix the 3.12 issue. Lets wait until it got landed to see what's remaining and if we can reproduce the issue with Python 3.11.

Depends on: 1917556

Sam, I was trying to reproduce the issue on Python 3.11, but the test runs fine for me. Can you check again on a clean central? It sounds odd that an error such as invalid decimal literal would only happen on 3.11 locally and not on CI.

Flags: needinfo?(sfoster)

(In reply to Julian Descottes [:jdescottes] from comment #3)

Sam, I was trying to reproduce the issue on Python 3.11, but the test runs fine for me. Can you check again on a clean central? It sounds odd that an error such as invalid decimal literal would only happen on 3.11 locally and not on CI.

Ok yeah I think I had a local change on that last run. With a clean central, test_quit_restart.py runs and passes with python 3.11

Flags: needinfo?(sfoster)

Thanks for checking, Sam! Great to see you’ve got it fixed for Python 3.11. Since we have bug 1917556 (by coincidence) for Python 3.12, and it’s unrelated to the 3.11 issue described here, let’s update this bug’s summary to focus on the invalid decimal literal topic.

Status: NEW → RESOLVED
Closed: 2 months ago
No longer depends on: 1917556
Resolution: --- → INVALID
Summary: marionette-test throws "AttributeError: module 'unittest' has no attribute '_TextTestResult'. Did you mean: 'TextTestResult'?" with python3.12 on macos → SyntaxError: invalid decimal literal File "testing/marionette/mach_commands.py", line 113, in marionette_test
You need to log in before you can comment on or make changes to this bug.