New issue
Advanced search Search tips

Issue 783704 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Closed: Jun 2018
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Chrome
Pri: 3
Type: Bug



Sign in to add a comment

pytests: Deprecate 'optional'

Project Member Reported by hungte@chromium.org, Nov 10 2017

Issue description

Currently pytests Args support both 'optional' and 'default'.

However, the args are redundant. If an Arg has default value, then it's indeed optional (to test list args).

And if it's optional=True without default, it's slightly unclear for what its value will be (current implementation is None).

As a result, I think it may be more clear if we keep only default and abandon optional.

This should be a pytest only change, and not changing test lists.
 

Comment 1 by hungte@chromium.org, Nov 10 2017

Feel free to let me know if anyone can think of a case that both attributes should be needed!

Comment 2 by youcheng@google.com, Nov 10 2017

We can have a special value NO_DEFAULT (like an unique string or object), which means the argument is required, as the default value of parameter 'default' of Args.
so default=None means the default value is really None.

Comment 3 by pihsun@chromium.org, Nov 10 2017

re #2, it's already the case (since CL:406818), so the 'optional' is purely redundant now since Arg('a', 'b', optional=True) is same as Arg('a', 'b', default=None).

Comment 4 by youcheng@google.com, Nov 10 2017

Cool. I didn't notice that change :p

Comment 5 by hungte@chromium.org, Nov 10 2017

Right. If you are declaring a 'default' argument, then it's apparently optional in test list args.

And if you want to declare an argument as "optional", then it's definitely easier to give it a default in ARG and then check that in pytest.

Having one argument declared as optional without values is weird does not make sense (since you have to check it somewhere in pytest anyway).

Comment 6 by youcheng@google.com, Nov 10 2017

Thanks for clarification.
Then I agree that we can totally abandon argument 'optional' now.
Currently after dealing with _DEFAULT_NO_SET, (default, optional) being (None, True) and (None, False) have different meaning. One is set by default=None, the other is set by not giving the default value.

Is the optional flag still needed to separate these two cases?

Comment 8 by pihsun@chromium.org, Nov 13 2017

I think we should prohibit the use of (default=None, optional=False), and test should just don't write the default in this case.

Comment 9 by stimim@chromium.org, Nov 13 2017

(None, False) means the argument is not optional, I think we still don't need optional flag in this case (at least not a public flag).

Comment 10 Deleted

(None, True) implies "this value is optional and the default should be None" => default=None

(None, False) implies "this value is not optional but I'm feeding a default value here as None" => which should be abandoned by removing default=None.
re #8, sorry it's a bit confusing, I meant using

Arg(name, type, help, default=None) and Arg(name, type, help)

will have (self.default, self.optional) being (None, True) and (None, False).

re #9, yes we can use a private flag. Just to be sure that this flag is still needed. Thanks!
Well you can also just keep the self.default as DEFAULT_NO_SET, and there's no need for a separate private flag.
Both way works though.
Project Member

Comment 14 by bugdroid1@chromium.org, Nov 23 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/platform/factory/+/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4

commit 7e4441f0a75db8d8170cc1925c5e63758b0fc6a4
Author: Cheng-Han Yang <chenghan@google.com>
Date: Thu Nov 23 20:46:57 2017

arg_utils: Deprecate 'optional' in Arg

The 'optional' and 'default' args in Arg are redundant. If an Arg has
default value, it is indeed optional. To set an Arg as optional, provide
a default value (can be None). If an Arg does not have a default value,
it is not optional.

BUG= chromium:783704 
TEST=make test

Change-Id: I3fdb975619fb9a8c18ce05cac50e310a934b3037
Reviewed-on: https://chromium-review.googlesource.com/778602
Commit-Ready: Cheng-Han Yang <chenghan@chromium.org>
Tested-by: Cheng-Han Yang <chenghan@chromium.org>
Reviewed-by: Yong Hong <yhong@google.com>

[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/audio.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/i18n/arg_utils.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/power_under_stress.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/display_point.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/probe/functions/i2c.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/lid_switch/lid_switch.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/touchpad_hover.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/probe_sim.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/instalog/plugins/input_time.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/device/camera.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/keyboard_smt.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/gps/gps.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/verify_root_partition.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/charger.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/flash_netboot.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/instalog/plugins/output_stdout.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/ping_test.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/rf_graphyte/rf_graphyte.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/suspend_resume.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/utils/arg_utils.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/instalog/plugins/output_socket.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/update_cr50_firmware.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/brightness/lcd_backlight.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/instalog/plugins/input_pull_socket.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/wifi_throughput.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/write_device_data_to_vpd.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/instalog/plugins/output_bigquery.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/probe/functions/edid.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/start/start.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/stylus.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/instalog/plugins/input_archive.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/removable_storage/removable_storage.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/doc/generate_rsts.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/bad_blocks.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/instalog/plugins/output_http.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/plankton_charge.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/led/led.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/fan_speed.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/usb.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/plankton_cc_flip_check.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/instalog/plugins/input_log_file.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/bft_fixture.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/pointing_device.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/external_display.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/vswr/vswr.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/button.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/instalog/plugins/input_socket.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/battery_cycle.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/instalog/plugins/input_drm_screencap/input_drm_screencap.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/finalize/finalize.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/probe/functions/input_device.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/touchpad.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/thermal_slope.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/camera.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/cellular_switch_firmware.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/gyroscope.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/light_sensor_calibration.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/accelerometers_calibration.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/thermal_sensors.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/hwid_v3.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/bluetooth_host.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/instalog/plugins/output_pull_socket.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/ethernet.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/countdown.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/shopfloor_service.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/update_kernel.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/bluetooth.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/ac_power.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/video_playback.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/compass.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/instalog/plugins/output_gcs.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/accelerometers_lid_angle.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/instalog/plugins/input_http.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/read_device_data_from_vpd.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/probe/function.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/summary/summary.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/keyboard/keyboard.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/sync_time.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/exec_shell.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/touchscreen.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/instalog/plugins/input_health.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/interrupt/interrupt.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/instalog/plugins/output_archive.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/scan/scan.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/tablet_rotation.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/light_sensor.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/message/message.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/audio_loop/audio_loop.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/station_entry.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/probe/probe.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/touchscreen_calibration/touchscreen_calibration.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/verify_components.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/wireless_antenna.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/audio_basic.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/sample_customized_test.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/backlight.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/wait_external_test.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/wireless_radiotap.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/plankton_display.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/battery_sysfs.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/probe/functions/sysfs.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/tablet_mode.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/buzzer.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/battery_current.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/shutdown/shutdown.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/instalog/plugins/buffer_simple_file/buffer_simple_file.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/update_device_data.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/thermal_load.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/retrieve_config.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/battery_basic.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/line_check_item.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/utils/arg_utils_unittest.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/verify_value.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/lte_verify_config.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/offline_test/shell/deploy.py
[modify] https://crrev.com/7e4441f0a75db8d8170cc1925c5e63758b0fc6a4/py/test/pytests/audio_quality.py

Project Member

Comment 15 by bugdroid1@chromium.org, Mar 30 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/platform/factory/+/e53c1df239ed270b419190e156e10a6f5791e112

commit e53c1df239ed270b419190e156e10a6f5791e112
Author: Yong Hong <yhong@chromium.org>
Date: Fri Mar 30 13:36:12 2018

doc: Fix rendering error on optional test arguments.

An argument has a default value if and only if the argument is an
optional argument.  Therefore, we should determine whether to print
the default value or not by ``arg.IsOptional()`` instead of
``bool(arg.default)``.

BUG= chromium:783704 
TEST=make doc

Change-Id: I55afb67c6fa02a963d439200b55127f13935be61
Reviewed-on: https://chromium-review.googlesource.com/987418
Commit-Ready: Yong Hong <yhong@google.com>
Tested-by: Yong Hong <yhong@google.com>
Reviewed-by: Cheng-Han Yang <chenghan@chromium.org>

[modify] https://crrev.com/e53c1df239ed270b419190e156e10a6f5791e112/py/doc/generate_rsts.py

Status: Fixed (was: Assigned)

Sign in to add a comment