Skip to content

Commit 593dbc4

Browse files
Add best practice documentation for existence checks before property access
1 parent dca7b05 commit 593dbc4

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

doc/source/modules.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ arguments of your test function to make it available within it.
1212
# [...]
1313
1414
15+
It is considered best practice to first check for the existence of a resource before accessing its properties. This ensures that the resource is available and prevents unexpected runtime errors, such as `RuntimeError` or `ValueError`, which can occur if it does not exist. By validating existence first, you make your code more robust and errors easier to understand.
16+
17+
.. code-block:: python
18+
19+
svc = host.service('non-existing')
20+
assert svc.exists
21+
assert svc.is_running
22+
23+
1524
host
1625
~~~~
1726

0 commit comments

Comments
 (0)