.. include:: Agenda: Python (2026-11-11 - 2026-11-13) ======================================== Labgrid/``pytest`` Course Project? ---------------------------------- A homogenous team does not want to walk through endless stupid exercises, so lets **try to define** a (semi) realistic project that we can use to get our fingers dirty, and add dynamicity to the course. For example (this is what I was able to bring home from our meeting on 2026-10-21), * Export test cases from Jira/Zephyr (https://www.youtube.com/watch?v=p0WXAHC4cIo) * Parse exported, convert to (interpret with?) ``pytest`` * Fixtures: acquiring resources in Labgrid * Labgrid "strategy"? (`Labgrid Tutorial #4 - Write Your Own Strategy `__) Day 1 ----- Basics ...... This is everything that's in :doc:`/trainings/material/soup/python/basics/index`. Chances are that boring basics will be covered quickly and we can move on to more interesting topics. Nonetheless we don't let anyone get through without knowing what (im)mutability is, for example, or what a variable is, and where the types are. * :doc:`/trainings/material/soup/python/basics/installation` * :doc:`/trainings/material/soup/python/basics/python_0110_blahblah/topic` * :doc:`/trainings/material/soup/python/basics/python_0120_helloworld/topic` * :doc:`/trainings/material/soup/python/basics/python_0125_running/topic` * :doc:`/trainings/material/soup/python/basics/python_0130_syntax_etc/topic` * :doc:`/trainings/material/soup/python/basics/python_0139_commandline_argv/topic` * :doc:`/trainings/material/soup/python/basics/python_0140_variables/topic` * :doc:`/trainings/material/soup/python/basics/python_0150_datatypes_overview/topic` * :doc:`/trainings/material/soup/python/basics/python_0150_datatypes_overview_compound/topic` * :doc:`/trainings/material/soup/python/basics/python_0160_boolean/topic` * :doc:`/trainings/material/soup/python/basics/python_0170_if/topic` * :doc:`/trainings/material/soup/python/basics/python_0193_while/topic` * :doc:`/trainings/material/soup/python/basics/python_0200_sequential_types/topic` * :doc:`/trainings/material/soup/python/basics/python_0210_indexing_slicing/topic` * :doc:`/trainings/material/soup/python/basics/python_0220_for/topic` * :doc:`/trainings/material/soup/python/basics/python_0225_range/topic` * :doc:`/trainings/material/soup/python/basics/python_0250_refs_flat_deep_copy/topic` * :doc:`/trainings/material/soup/python/basics/python_0270_functions/topic` * :doc:`/trainings/material/soup/python/basics/python_0300_strings/topic` * :doc:`/trainings/material/soup/python/basics/python_0310_strings_formatting/topic` * :doc:`/trainings/material/soup/python/basics/python_0320_strings_methods/topic` * :doc:`/trainings/material/soup/python/basics/python_0400_lists/topic` * :doc:`/trainings/material/soup/python/basics/python_0450_dictionaries/topic` * :doc:`/trainings/material/soup/python/basics/python_0460_sets/topic` * :doc:`/trainings/material/soup/python/basics/python_0500_files/topic` * :doc:`/trainings/material/soup/python/basics/python_1000_function_objects/topic` * :doc:`/trainings/material/soup/python/advanced/comprehensions/topic` .. _2026-11-11-csv-json: File I/O (CSV And JSON), ``pytest``, Virtual Environments ......................................................... .. topic:: Exercise Time There is no course material covering CSV and JSON (it's really so simple). There is a reason why these topics have been requested though, so lets see how we can use the knowledge from the "Basics" section and bring our course project further. This is likely going to be something like parsing CSV and JSON formats - which is always nasty (because boring) and error prone. Lets enter test driven development, and see what pytest can do for us (using Labgrid with ``pytest`` is a separate topic - no Labgrid yet in sight). * :doc:`/trainings/material/soup/python/swdev/pytest/intro` (mention :doc:`/trainings/material/soup/python/swdev/unittest`, only to say ``pytest`` is much better) * :doc:`/trainings/material/soup/python/swdev/pip/topic` * :doc:`/trainings/material/soup/python/swdev/venv/topic` Day 2 ----- Object Oriented Programming, Exception Handling ............................................... Covering the basics of OO. This is what people need most, if only to structure code readably. From :doc:`/trainings/material/soup/python/advanced/oo/index`: * :doc:`/trainings/material/soup/python/advanced/oo/classes-and-dicts/topic` * :doc:`/trainings/material/soup/python/advanced/oo/constructor/topic` * :doc:`/trainings/material/soup/python/advanced/oo/methods/topic` * :doc:`/trainings/material/soup/python/advanced/oo/properties/topic` * :doc:`/trainings/material/soup/python/advanced/exceptions/topic` .. topic:: Exercise Time * Use our test-driven-development skills to transform the :ref:`code from yesterday <2026-11-11-csv-json>` into OO. * If applicable, we could write some nice commandline frontends to, for example, interactively export Jira/Zephyr test cases. (Use `Click `__ to parse args, *and not* :doc:`argparse `) .. note:: More OO Topics There's more in :doc:`/trainings/material/soup/python/advanced/oo/index`. Lets ignore this for a while, and watch out for opportunities to cover it too. * :doc:`/trainings/material/soup/python/advanced/oo/str-repr/topic` * :doc:`/trainings/material/soup/python/advanced/oo/namedtuple/topic` * :doc:`/trainings/material/soup/python/advanced/oo/inheritance/topic` * :doc:`/trainings/material/soup/python/advanced/oo/operator-overloading/topic` * :doc:`/trainings/material/soup/python/advanced/oo/abc/topic` Modules And Packages .................... Not knowing better, we have put all code in one flat directory. Tests, code/classes, and commandline programs. Restructure the mess, talking about project structure, making recommendations. * :doc:`/trainings/material/soup/python/advanced/modules` Logging ....... Introduce logging into our growing application, covering parse errors, network errors, and all such external nastities. .. note:: **TODO** Create material about the Python ``logging`` package Decorators (The ``@`` In A Fixture) ................................... Answering the question "What's the ``@`` when I write a ``pytest`` fixture?", lets go over something surprisingly simple. * :doc:`/trainings/material/soup/python/advanced/starargs/topic` * :doc:`/trainings/material/soup/python/advanced/closures/topic` * :doc:`/trainings/material/soup/python/advanced/decorators/topic` Generators ("Yield" Fixtures) ............................. In ``pytest``, one can comfortably cut a fixture "function" in two halves - the setup and the teardown part - by calling ``yield`` in the middle. Technically, the "function" has become a *generator*. There are more uses for ``yield`` than cutting a function in two - lets cover generators in detail. * :doc:`/trainings/material/soup/python/advanced/iteration-generation/topic` Day 3 ----- Project Time ............ .. topic:: Exercise Time Time to approach Labgrid together with ``pytest``? Context Managers ................ Although resource management is easier than in other languages, it is easy enough to mess it up. Clarify the ominous ``with`` statement, and see what is under the hood (spoiler: ``yield`` cuts again). * :doc:`/trainings/material/soup/python/advanced/context-mgr/topic` Into The Wild ............. Lets leave room on day 3 to ... * Try out things. We just went into Labgrid coding; there might well be opportunities to spend more course time. * Cover yet-uncovered material .. Bernd (?) .. ......... .. .. * Development environment: Python, VS Code, virtual environments (venv), pip .. .. **Have** .. .. * Basic understanding of classes and objects .. * Exception handling (try/except) and error management .. * Reading and writing files (JSON, CSV, text files) .. * Logging and debugging using breakpoints .. * Modules, imports, and Python project structure .. .. pSri .. ... .. .. **Have** .. .. * Logging .. * File handling .. * error codes (-> exceptions) .. * testing .. * custom exceptions .. * Error handling .. .. **Dunno** .. .. * Debugging .. .. * API failures .. * network failures .. * external systems .. * security .. * reliability .. * extensibility .. * best practices .. .. Maxim .. ..... .. .. **Have** .. .. .. list-table:: .. :align: left .. .. * * Topic .. * Priority .. * Details .. * * pytest .. * Essential .. * Test structure, assertions, fixtures, parametrization, reports, .. * * Functions, modules, imports .. * Essential .. * Understand and maintain generated scripts .. * * Exceptions (try/except/finally) .. * Essential .. * Distinguish DUT failures from automation failures; guarantee cleanup .. * * OOP: classes and interfaces .. * High .. * Understand labgrid drivers, targets and reusable test infrastructure .. * * File I/O, dictionaries, lists .. * Essential .. * Process configuration, logs, test results and JSON .. * * Context managers (with) .. * High .. * Safely manage connections, temporary files and hardware resources .. * * Decorators .. * High .. * Understand @pytest.fixture, @pytest.mark.parametrize .. * * Generators, yield .. * High .. * Understand pytest fixtures with setup and teardown .. * * Virtual environments, dependencies .. * High .. * Keep tests reproducible on different machines .. ..