You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Create the extension and set its data by clicking on the "Generate" button
336
+
extension = MyExtension()
337
+
extension.root.nametowidget("generate").invoke()
338
+
339
+
# Check that the extension logic executes correctly
340
+
assert2==len(aedt_app.variable_manager.variables)
341
+
assert main(extension.data)
342
+
assert7==len(aedt_app.variable_manager.variables)
343
+
344
+
Run tests in VSCode and PyCharm
345
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
346
+
347
+
This section explains how to run pytest unit and system tests in VSCode (Visual Studio Code) and PyCharm, and how to estimate coverage
348
+
using the "Run with coverage" feature or pytest-cov.
349
+
350
+
Prerequisites
351
+
~~~~~~~~~~~~~
352
+
- Install pytest and pytest-cov in your environment if you haven't already:
353
+
354
+
.. code:: bash
355
+
356
+
pip install pytest pytest-cov
357
+
358
+
- Ensure your IDE is configured to use the Python interpreter where the packages are installed.
359
+
360
+
VSCode IDE
361
+
~~~~~~~~~~~~~~~~~~~~~~~
362
+
363
+
1. Use the Test Explorer (Python extension) to discover and run tests:
364
+
- Open the Testing side bar (beaker icon).
365
+
- Run or debug individual tests, test files, or test suites from the UI.
366
+
367
+
.. image:: ../Resources/vscode_run_tests.png
368
+
:alt:VSCode Test Explorer (placeholder)
369
+
370
+
2. Run tests and view coverage using the GUI
371
+
- VSCode:
372
+
- Click the "Run Test with Coverage" button in the Test Explorer toolbar to run one or more tests with coverage.
373
+
- After the tests complete, a coverage summary appears in the Test Explorer (coverage % by file), and covered/uncovered lines are highlighted in the editor.
374
+
375
+
.. image:: ../Resources/coverage_vscode.png
376
+
:alt:VSCode Test Explorer (placeholder)
377
+
378
+
Brief note
379
+
~~~~~~~~~~
380
+
You can also run tests with coverage from a terminal in VSCode using pytest-cov:
- Coverage percentage shows the portion of executed lines compared to total executable lines in the source files.
414
+
- Higher coverage is generally better, but 100% coverage does not guarantee bug-free code. At least 85% coverage for all the new code added to the repository is required.
415
+
- Use ``--cov-report=term-missing`` to see which lines are not covered directly in the terminal.
416
+
- Use ``--cov-report=html`` and open ``htmlcov/index.html`` in a browser for an easy-to-navigate, per-file coverage report.
417
+
- Run unit and system tests separately to estimate their individual contributions:
418
+
419
+
Best practices
420
+
~~~~~~~~~~~~~~
421
+
- Aim to keep unit tests fast and isolated; use mocks for external systems like AEDT.
422
+
- Use the IDE "Run with coverage" feature for quick, visual feedback.
343
423
344
424
Step 4: Add the extension to the catalog
345
425
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -373,3 +453,71 @@ Also, another card should be added to the
373
453
``doc/source/User_guide/pyaedt_extensions_doc/project/index.rst`` file to link to the extension's documentation page.
374
454
This ensures that the extension is discoverable in the documentation from the multiple pages that list all the
375
455
extensions available in PyAEDT.
456
+
457
+
458
+
Local testing parameters
459
+
------------------------
460
+
461
+
Two configuration files control test behavior:
462
+
463
+
- ``tests/local_config.json``: Contains parameters intended for modification during local testing.
464
+
These settings control test execution behavior such as desktop version, graphical mode, and feature flags.
465
+
**This file does not exist by default and must be created manually** in the ``tests/`` directory.
466
+
467
+
- ``tests/pyaedt_settings.yaml``: Contains default PyAEDT settings applied to all tests.
468
+
These settings are not intended for local modification.
469
+
470
+
Creating local_config.json
471
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
472
+
473
+
To customize local test execution, create a ``local_config.json`` file in the ``tests/`` directory
474
+
at the top level of the repository. Below is an example configuration with descriptions of each parameter:
475
+
476
+
.. code-block:: json
477
+
478
+
{
479
+
"desktopVersion": "2025.2",
480
+
"NonGraphical": true,
481
+
"NewThread": true,
482
+
"skip_circuits": false,
483
+
"use_grpc": true,
484
+
"close_desktop": true,
485
+
"use_local_example_data": false,
486
+
"local_example_folder": "",
487
+
"skip_modelithics": true
488
+
}
489
+
490
+
Parameter descriptions:
491
+
492
+
- ``desktopVersion``: AEDT version to use for testing (for example, "2025.2," "2024.1").
493
+
- ``NonGraphical``: When ``true``, runs AEDT in non-graphical mode (headless).
494
+
- ``NewThread``: Opens AEDT in a new thread.
495
+
- ``skip_circuits``: When ``true``, skips Circuit-related tests.
496
+
- ``use_grpc``: When ``true``, uses gRPC API for communication with AEDT.
497
+
- ``close_desktop``: When ``true``, closes AEDT after tests complete.
498
+
- ``use_local_example_data``: When ``true``, uses local example data for tests.
499
+
- ``local_example_folder``: Path to the local example data folder.
500
+
- ``skip_modelithics``: When ``true``, skips Modelithics-related tests.
501
+
502
+
Replicating CI/CD environment
503
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
504
+
505
+
The CI/CD pipeline loads ``pyaedt_settings.yaml`` via the environment variable:
0 commit comments