Skip to content

Add doctests#8072

Open
jenshnielsen wants to merge 8 commits intomicrosoft:mainfrom
jenshnielsen:add_doctests
Open

Add doctests#8072
jenshnielsen wants to merge 8 commits intomicrosoft:mainfrom
jenshnielsen:add_doctests

Conversation

@jenshnielsen
Copy link
Copy Markdown
Collaborator

Convert several inline examples to doctests and execute these in CI

  • Document change in exception in config

DotDict.__getattr__ was propagating KeyError from __getitem__ when
accessing missing attributes. Python's attribute protocol requires
AttributeError for missing attributes, otherwise hasattr() and
inspect.unwrap() break. This caused --doctest-modules to fail with
'KeyError: __wrapped__' when collecting test files.
- Convert illustrative docstring examples from >>> syntax to
  .. code-block:: python to prevent them being parsed as doctests
- Add # doctest: +SKIP for simple single-line illustrative examples
- Fix _SetParamContext docstring whitespace inconsistency
- Add conftest.py to ignore instrument drivers requiring optional
  dependencies (gclib, clr/pythonnet, pywin32) during collection
Convert 14 examples from .. code-block:: python back to executable
>>> doctest syntax in cases where no hardware or complex external
state is needed:

- validators: MultiType, MultiTypeOr, MultiTypeAnd
- field_vector: set_vector, set_component
- parameter_base: set_to, restore_at_exit
- parameter: sweep
- sweep_values: make_sweep
- stahl: chain
- threading_utils: RespondingThread
- logger: LogCapture
- lakeshore_base: _get_sum_terms
- keysight_e4980a: KeysightE4980AMeasurementPair

5 examples remain as skipped or code-blocks because they require
instruments, database infrastructure, or produce complex output
(Config.add, guids_from_list_str, DataSaver.add_result,
Instrument.close_all, partial_with_docstring).
Dynamically detect deprecated driver alias modules (those containing
'module is deprecated') and exclude them from doctest collection.
This eliminates 14 QCoDeSDeprecationWarning warnings that were triggered
just by importing these modules during pytest --doctest-modules.
Replace jumanjihouse/pre-commit-hooks (requires Docker or system
shellcheck) with shellcheck-py/shellcheck-py which provides a
pip-installable shellcheck binary for macOS, Linux, and Windows.
@jenshnielsen jenshnielsen requested a review from a team as a code owner April 28, 2026 04:54
>>> get_sum_terms(terms, 96)
... [64, 32] # This is correct because 96=64+32
>>> [int(x) for x in LakeshoreBaseSensorChannel._get_sum_terms(terms, 96)]
[64, 32]
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Readd comment

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

❌ Patch coverage is 89.47368% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.60%. Comparing base (b744146) to head (9b4b135).
⚠️ Report is 34 commits behind head on main.

Files with missing lines Patch % Lines
src/qcodes/instrument_drivers/conftest.py 86.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8072      +/-   ##
==========================================
+ Coverage   70.59%   70.60%   +0.01%     
==========================================
  Files         333      334       +1     
  Lines       32490    32508      +18     
==========================================
+ Hits        22936    22952      +16     
- Misses       9554     9556       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant