-
Notifications
You must be signed in to change notification settings - Fork 191
Guide to move existing Python2 framework to Python3
This is a basic guide on steps you can follow to move your existing Python2 to Python3 framework.
1. The first step is auto-converting Python2 code to Python3 code. Futurize tool can be used for achieving this. It takes care of import statement changes, syntax changes for print and exception statements. You can follow the below steps to achieve this
a. Install future
pip install future
b. Run futurize after navigating to your current project
futurize --stage1 -w qxf2-page-object-model
That was simple. The tool helps to make most of the changes including print, import statements, the way we handle exception statements etc.
2. Replace some files in Page_Objects which are not dependent on your project Some files in Page_Objects like Base_Page and DriverFactory can be replaced directly from our current Python3 framework. In case you have made some changes to these files, you can't replace the files directly. Some important changes we did for Base_Page.py is iteritems() changed to items()
Some other changes we made to our tests were related to using split and zip functions differently in Python3
3. Changes which needs to be done for tests Since tests are specific to the application under tests, you need to make the changes in addition to what futurize tool has done to make it compatible for Python3. Decoding the byte string as string was one additional thing which we had to do for our test
4. Copying Util files. Most of the util files you can directly replace from our current Python3 framework. In case you have any additional utility files you may need to change it.
5. Copying requirements.txt. requirements.txt can be copied directly from Python3 framework. All latest versions are updated there.
6. Changes to conftest.py In conftest.py, mainly import statements are changed according to Python3.
7. Changes for API endpoints We have stopped using Base_Mechanize as Python3 does not support Mechanize module. We have replaced it with the Requests module. You can replace Base_Mechanize with Base_API. All your other endpoint files need to import Base_API and there may be some changes which you may need to make to comply with Requests module.
Eg: For our Cars_API_Endpoints: Import statement had to be changed from Base_Mechanize to Base_API.
All methods like add_car, get_cars, get_car, update_car need to be updated for json_response and return according to with the get, post, put, delete methods in Base_API.
API_Interface: Futurize tool take care of Syntax conversions.
API_Player : Methods get_car_count and get_regi_car_count are added to get the initial car count dynamically. Methods need to be copied from API_Player are get_car_count and get_regi_car_count.
In other methods, get_cars, get_car etc, json_response and result_flag is modified according to changes in Base_API. So API_Player can be replaced with API_Player in Python3 Framework.
Cars_API_Endpoints: Import statement need to be changed from Base_Mechanize to Base_API.
All methods like add_car, get_cars,get_car,update_car need to be updated for json_response and return according to with the get,post,put,delete methods in Base_API.
Registration_API_Endpoints: Import statement need to be changed from Base_Mechanize to Base_API.
response and json_response need to be modified under register_car method.
response need to be modified under delete_registered_car.
User_API_Endpoints: Import statement need to be changed from Base_Mechanize to Base_API.
8. Deleting the unwanted files. All the import functions defined after future import need to be deleted, like from future import absolute_import.