Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ac1a931
Removed build_machine parameter
eblanco-ansys Sep 29, 2025
c473b0a
Removed skip_space_claim parameter
eblanco-ansys Sep 29, 2025
a119deb
Removed skip_edb parameter
eblanco-ansys Sep 29, 2025
fb7bb2c
Removed skip_debug parameter
eblanco-ansys Sep 29, 2025
4c4fb76
Removed local parameter
eblanco-ansys Sep 29, 2025
2d608a0
Removed skip_desktop_test parameter
eblanco-ansys Sep 29, 2025
e7fd241
Merge branch 'main' into refactor/outdated-local-config-parameters
eblanco-ansys Oct 1, 2025
a4ff090
Refactored conftest to be unified
eblanco-ansys Oct 2, 2025
cf6bfd1
Merge branch 'main' into refactor/outdated-local-config-parameters
eblanco-ansys Oct 2, 2025
6d13be5
CHORE: Auto fixes from pre-commit hooks
pre-commit-ci[bot] Oct 2, 2025
fa3eb44
Updated conftest docs AEDT version
eblanco-ansys Oct 2, 2025
b996eaf
Merge branch 'refactor/outdated-local-config-parameters' of https://g…
eblanco-ansys Oct 2, 2025
d47ac49
chore: adding changelog file 6727.miscellaneous.md [dependabot-skip]
pyansys-ci-bot Oct 2, 2025
58826ac
chore: adding changelog file 6727.miscellaneous.md [dependabot-skip]
pyansys-ci-bot Oct 2, 2025
6c8ea24
Fixes
eblanco-ansys Oct 6, 2025
710be46
Merge branch 'main' into refactor/outdated-local-config-parameters
eblanco-ansys Oct 6, 2025
686b6e1
CHORE: Auto fixes from pre-commit hooks
pre-commit-ci[bot] Oct 6, 2025
135d0c9
Fixes
eblanco-ansys Oct 6, 2025
34c41bd
Merge branches 'refactor/outdated-local-config-parameters' and 'refac…
eblanco-ansys Oct 6, 2025
117cb02
Fixes
eblanco-ansys Oct 6, 2025
859a5ea
Refactor test marker assignment to use constants instead of string li…
eblanco-ansys Oct 8, 2025
11a1e9b
Fixed example folders
eblanco-ansys Oct 9, 2025
895c83b
Merge branch 'main' into refactor/outdated-local-config-parameters
eblanco-ansys Oct 9, 2025
84ad71b
CHORE: Auto fixes from pre-commit hooks
pre-commit-ci[bot] Oct 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Run unit tests
env:
PYAEDT_LOCAL_SETTINGS_PATH: 'tests/pyaedt_settings.yaml'
uses: ansys/actions/tests-pytest@c2fa7c93f6883114e0e643599431b33d29f0b13f # v10.1.4
with:
pytest-postargs: 'tests/unit'
Expand Down Expand Up @@ -267,6 +269,7 @@ jobs:
- name: Run tests marked with 'solvers'
env:
PYTHONMALLOC: malloc
PYAEDT_LOCAL_SETTINGS_PATH: 'tests/pyaedt_settings.yaml'
run: |
.venv\Scripts\Activate.ps1
pytest ${{ env.PYTEST_ARGUMENTS }} --timeout=600 -m solvers
Expand Down Expand Up @@ -331,6 +334,7 @@ jobs:
- name: Run tests marked with 'solvers'
run: |
export LD_LIBRARY_PATH=${{ env.ANSYSEM_ROOT252 }}/common/mono/Linux64/lib64:$LD_LIBRARY_PATH
export PYAEDT_LOCAL_SETTINGS_PATH='tests/pyaedt_settings.yaml'
source .venv/bin/activate
pytest ${{ env.PYTEST_ARGUMENTS }} --timeout=600 -m solvers

Expand Down Expand Up @@ -399,6 +403,7 @@ jobs:
uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3.0.2
env:
PYTHONMALLOC: malloc
PYAEDT_LOCAL_SETTINGS_PATH: 'tests/pyaedt_settings.yaml'
with:
max_attempts: 2
retry_on: error
Expand Down Expand Up @@ -479,6 +484,7 @@ jobs:
timeout_minutes: 40
command: |
export LD_LIBRARY_PATH=${{ env.ANSYSEM_ROOT252 }}/common/mono/Linux64/lib64:$LD_LIBRARY_PATH
export PYAEDT_LOCAL_SETTINGS_PATH='tests/pyaedt_settings.yaml'
source .venv/bin/activate
pytest ${{ env.PYTEST_ARGUMENTS }} -n 4 --dist loadfile --timeout=600 -m general

Expand Down Expand Up @@ -550,6 +556,7 @@ jobs:
uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3.0.2
env:
PYTHONMALLOC: malloc
PYAEDT_LOCAL_SETTINGS_PATH: 'tests/pyaedt_settings.yaml'
with:
max_attempts: 2
retry_on: error
Expand Down Expand Up @@ -631,6 +638,7 @@ jobs:
timeout_minutes: 40
command: |
export LD_LIBRARY_PATH=${{ env.ANSYSEM_ROOT252 }}/common/mono/Linux64/lib64:$LD_LIBRARY_PATH
export PYAEDT_LOCAL_SETTINGS_PATH='tests/pyaedt_settings.yaml'
source .venv/bin/activate
pytest ${{ env.PYTEST_ARGUMENTS }} -n 4 --dist loadfile --timeout=600 -m visualization -x

Expand Down Expand Up @@ -699,6 +707,7 @@ jobs:
uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3.0.2
env:
PYTHONMALLOC: malloc
PYAEDT_LOCAL_SETTINGS_PATH: 'tests/pyaedt_settings.yaml'
with:
max_attempts: 2
retry_on: error
Expand Down Expand Up @@ -784,6 +793,7 @@ jobs:
timeout_minutes: 120
command: |
export LD_LIBRARY_PATH=${{ env.ANSYSEM_ROOT252 }}/common/mono/Linux64/lib64:$LD_LIBRARY_PATH
export PYAEDT_LOCAL_SETTINGS_PATH='tests/pyaedt_settings.yaml'
source .venv/bin/activate
xvfb-run pytest ${{ env.PYTEST_ARGUMENTS }} --timeout=600 -m extensions

Expand Down Expand Up @@ -852,6 +862,7 @@ jobs:
uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3.0.2
env:
PYTHONMALLOC: malloc
PYAEDT_LOCAL_SETTINGS_PATH: 'tests/pyaedt_settings.yaml'
with:
max_attempts: 2
retry_on: error
Expand Down Expand Up @@ -925,6 +936,7 @@ jobs:
uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3.0.2
env:
PYTHONMALLOC: malloc
PYAEDT_LOCAL_SETTINGS_PATH: 'tests/pyaedt_settings.yaml'
with:
max_attempts: 2
retry_on: error
Expand Down
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,11 @@ dist/
/htmlcov/
/coverage.xml
/tests/system/general/coverage.xml
/tests/system/general/local_config.json
/tests/system/solvers/coverage.xml
/tests/system/solvers/local_config.json
/tests/unit/coverage.xml
test-results.xml
test-output.xml
*local_config.json

# Scratch Jupyter Notebooks
scratch_notebooks/
Expand All @@ -397,13 +396,10 @@ model.index\+

# local environment settings used by e.g. Visual Studio Code
/.env
/doc/source/local_config.json
/.venv*

# test coverage output
/.cov/
/tests/system/visualization/local_config.json
/tests/system/general/pyaedt_settings.yaml

# Custom instructions for GitHub Copilot
.github/copilot-instructions.md
1 change: 1 addition & 0 deletions doc/changelog.d/6727.miscellaneous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Conftest refactoring and local_config cleaning
115 changes: 111 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,24 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import json
import os
from pathlib import Path
import random
import shutil
import string
import sys
import tempfile
from typing import List
from unittest.mock import MagicMock

import pytest

from ansys.aedt.core.aedt_logger import pyaedt_logger
from ansys.aedt.core.generic.settings import settings
from ansys.aedt.core.internal.filesystem import Scratch

# Test category prefixes for marker assignment
UNIT_TEST_PREFIX = "tests/unit"
INTEGRATION_TEST_PREFIX = "tests/integration"
SYSTEM_TEST_PREFIX = "tests/system"
Expand All @@ -39,6 +51,67 @@
EMIT_TEST_PREFIX = "tests/system/emit"


DEFAULT_CONFIG = {
"desktopVersion": "2025.2",
"NonGraphical": True,
"NewThread": True,
"use_grpc": True,
"close_desktop": True,
"remove_lock": False,
"disable_sat_bounding_box": True,
"use_local_example_data": False,
"local_example_folder": None,
"skip_circuits": False,
"skip_modelithics": True,
}

# Load top-level configuration
local_path = Path(__file__).parent
local_config_file = local_path / "local_config.json"

config = DEFAULT_CONFIG.copy()
if local_config_file.exists():
try:
with open(local_config_file) as f:
local_config = json.load(f)
config.update(local_config)
except Exception: # pragma: no cover
pass

desktop_version = config.get("desktopVersion", DEFAULT_CONFIG.get("desktopVersion"))
NONGRAPHICAL = config.get("NonGraphical", DEFAULT_CONFIG.get("NonGraphical"))
new_thread = config.get("NewThread", DEFAULT_CONFIG.get("NewThread"))
settings.use_grpc_api = config.get("use_grpc", DEFAULT_CONFIG.get("use_grpc"))
close_desktop = config.get("close_desktop", DEFAULT_CONFIG.get("close_desktop"))
remove_lock = config.get("remove_lock", DEFAULT_CONFIG.get("remove_lock"))
settings.disable_bounding_box_sat = config.get(
"disable_sat_bounding_box", DEFAULT_CONFIG.get("disable_sat_bounding_box")
)
settings.use_local_example_data = config.get("use_local_example_data", DEFAULT_CONFIG.get("use_local_example_data"))
if settings.use_local_example_data:
settings.local_example_folder = config.get("local_example_folder", DEFAULT_CONFIG.get("local_example_folder"))

logger = pyaedt_logger
os.environ["PYAEDT_SCRIPT_VERSION"] = config.get("desktopVersion", DEFAULT_CONFIG.get("desktopVersion"))


# Add current path to sys.path for imports
sys.path.append(str(local_path))


def generate_random_string(length):
"""Generate a random string of specified length."""
characters = string.ascii_letters + string.digits
random_string = "".join(random.sample(characters, length))
return random_string


def generate_random_ident():
"""Generate a random identifier for test folders."""
ident = "-" + generate_random_string(6) + "-" + generate_random_string(6) + "-" + generate_random_string(6)
return ident


def pytest_collection_modifyitems(config: pytest.Config, items: List[pytest.Item]):
"""Hook used to apply marker on tests."""
for item in items:
Expand All @@ -64,8 +137,41 @@ def pytest_collection_modifyitems(config: pytest.Config, items: List[pytest.Item
item.add_marker(pytest.mark.emit)


# ================================
# SHARED FIXTURES
# ================================


@pytest.fixture(scope="session", autouse=True)
def init_scratch():
"""Initialize a global scratch directory for all tests."""
test_folder_name = "pyaedt_test" + generate_random_ident()
test_folder = Path(tempfile.gettempdir()) / test_folder_name
try:
os.makedirs(test_folder, mode=0o777)
except FileExistsError as e:
print(f"Failed to create {test_folder}. Reason: {e}")

yield test_folder

try:
shutil.rmtree(test_folder, ignore_errors=True)
except Exception as e:
print(f"Failed to delete {test_folder}. Reason: {e}")


@pytest.fixture(scope="module", autouse=True)
def local_scratch(init_scratch):
"""Provide a module-scoped scratch directory."""
tmp_path = init_scratch
scratch = Scratch(tmp_path)
yield scratch
scratch.remove()


@pytest.fixture
def touchstone_file(tmp_path):
"""Create a dummy touchstone file for testing."""
file_path = tmp_path / "dummy.s2p"
file_content = """
! Terminal data exported
Expand All @@ -80,6 +186,7 @@ def touchstone_file(tmp_path):

@pytest.fixture()
def patch_graphics_modules(monkeypatch):
"""Patch graphics modules to avoid headless env issues."""
modules = [
"matplotlib",
"matplotlib.pyplot",
Expand All @@ -100,9 +207,9 @@ def patch_graphics_modules(monkeypatch):

# Specific action to make a mock an attribute of another mock
mocks["matplotlib"].pyplot = mocks["matplotlib.pyplot"]
mocks["ansys.tools.visualization_interface"].backends = mocks["ansys.tools.visualization_interface.backends"]
mocks["ansys.tools.visualization_interface.backends"].pyvista = mocks[
"ansys.tools.visualization_interface.backends.pyvista"
]
viz_interface = mocks["ansys.tools.visualization_interface"]
viz_backends = mocks["ansys.tools.visualization_interface.backends"]
viz_interface.backends = viz_backends
viz_backends.pyvista = mocks["ansys.tools.visualization_interface.backends.pyvista"]

yield mocks
18 changes: 18 additions & 0 deletions tests/pyaedt_settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# PyAEDT settings configuration for test environment
# This file configures PyAEDT settings for all tests

log:
enable_local_log_file: false
enable_global_log_file: false
enable_desktop_logs: false

general:
number_of_grpc_api_retries: 6
retry_n_times_time_interval: 0.5
enable_error_handler: false
desktop_launch_timeout: 180
release_on_exception: false
wait_for_license: true
enable_pandas_output: true
lsf: {}
# LSF settings are kept at defaults for test environment
Loading
Loading