ECU-TEST technology update to Python 3

Dear ECU-TEST users,
in order to keep the product ECU-TEST up to date, it is necessary to update important underlying software technologies and to switch therefor to Python 3. Unfortunately, this new version of the language is not completely backward-compatible. Thus, user with ECU-TEST version lower than 8.0 are also affected, if they want to update their workspaces. In the following migration guide we have summarized the main reasons for the switch to Python 3 and name the most important effects on our users.

Your ECU-TEST team

The main reasons for the switch to Python 3

Python 2.7 EOL is January 1st, 2020
  • No more security updates for Python 2
  • New features will not be available for Python 2
Libraries are dropping their Python 2 support sooner than later

The main impacts for all users

  • All user code must be adapted accordingly to work in Python 3, for example as simple calculation steps in ECU-TEST

  • Screen shot (Calculation)

  • Make Python 3 part of your test project roadmap now!
  • Scheduling enough time in advance to change the affected scripts in your workspace. How much time you will need depends on the amount of Python extensions you have.

Example migration workflow

Each project is different. Therefore, we cannot provide a recipe for the transition from Python 2 to 3 that will work for sure in every context. However, here we present a list of steps that have worked quite well in several ECU-TEST engineering projects.

Step #1

Read about the changes from Python 2 to 3. Knowing the differences will be very helpful:

Step #2

Create a migration branch or copy of your workspace for the Python update. Be sure to keep a backup of your workspace.

Step #3

Open the workspace with ECU-TEST 8.0.

Step #4

Open the migration help.


Screen shot (Migration help)

Step #5

Press "start."


Screen shot (Start screen)

Step #6

Get some coffee. Seriously.

Step #7

The migration help will show you spots in your workspace where a change is probably needed.


Screen shot (Overview)

In the background, ECU-TEST uses the lib2to3 and converts all expressions you can use in your workspace. If lib2to3 advises a fix, the migration help will show you the specific spot.

Please beware that lib2to3 is not perfect and cannot guarantee a complete migration. It might fix many spots, but it won’t find every single one and could even change good code!

Step #8

Convert your packages steps.

Unfortunately, it is not possible to convert the expressions of your packages’ steps automatically. We advise this manual step for every package:


  • Open the package (double click or right click on the package)

    Screen shot (Open package)

  • Move the package to the right border to see both the migration help and the package
  • Double click on the spots in the migration helper and fix the issues

Step #9

Convert all other spots.

All other spots can be converted automatically with lib2to3:


  • Check the other tabs. If the found spots looks okay for you, press the “play”-button to convert all the spots from one tab.

    Screen shot (Change)

  • You can see a list of the files, which where changed.

    Screen shot (Change done)

  • Check the new file against the backup file with a diff tool (for example WinMerge)

    Screen shot (Win merge)

  • Revert lines which are not correct.

Step #10

Run your workspace and check the results. If you have different results, check the typical pitfalls to fix this issue.

Typical pitfalls

User utilities converting is not working

ERROR message:

..application.gui.dataViewer.DvUtilities.InitContent: a bytes-like object is required, not 'str’

The lib2to3 converts the Utilities. But instead of using StringIO, you have to change to BytesIO.

Not working example:
Typical pitfall #1

Fixed example:
Typical pitfall #2

ProjectAPI changed

ERROR message:

..lib.project.projectStep.ProjectGeneratorCycleSet.Run: CreateCycleData() got an unexpected keyword argument 'useObjectApi'

This is not a 2to3 problem. In ECU-TEST 8.0 we change the API for Project generators and Project package generators. The old generator has been removed in ECU-TEST 8.0. Default is now the ObjectAPI. The parameter to use the ObjectAPI is not needed longer. Just remove it.

useObjectAPI is now default:
Typical pitfall #3

Working example:
Typical pitfall #4

Exec works different

If you use exec(), please have a look here: Stack Overflow

Imports

Imports in Python3 are only relative or absolute:

Typical pitfall #5

Bus read steps

Lib2to3 suggests changes for bus read steps

  • with expectation ~Present~ using the “Wait until true” option
  • with expected values within a list of possible interpreted strings

These usually can still be interpreted by ECU-TEST 8.0 and don’t need to be changed manually.