Pcornel
Automation · Python Automation

Functions

Cheat sheet · https://pcornel.dk/topic.php?topic=5259

Back to the Topic

Answer

Python functions are defined with def, take positional and keyword arguments and return values. Small, focused functions with type hints make automation code easier to test and reuse.

Remember

  • Small, focused functions are easier to test.
  • Type hints document inputs and outputs.
  • Return values instead of printing.

First checks

  • python3 -c 'import inspect, m; print(inspect.signature(m.f))' — signature
  • Docstrings — documentation
  • pytest -k <function> — unit tests

Verify in this order

inputs → function → output/exception

Where it usually breaks

Input/desired state → request accepted → job/task terminal status → target object read-back → effective runtime state → original workload → regression/rollback readiness.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5259

Confirmation

Confirm action

Continue?