Skip to content

Add root conftest.py to fix sonic_ax_impl import during pytest collection#371

Open
yxieca wants to merge 1 commit intosonic-net:masterfrom
yxieca:fix/conftest-sys-path
Open

Add root conftest.py to fix sonic_ax_impl import during pytest collection#371
yxieca wants to merge 1 commit intosonic-net:masterfrom
yxieca:fix/conftest-sys-path

Conversation

@yxieca
Copy link
Copy Markdown
Contributor

@yxieca yxieca commented Apr 11, 2026

Description

On trixie (bookworm+) builds, the wheel build flow in sonic-buildimage runs:

pip install '.[testing]' → pip uninstall asyncsnmp → python -m pytest

After pip uninstall, sonic_ax_impl is removed from site-packages. Individual test files add src/ to sys.path, but tests/mock_tables/dbconnector.py imports sonic_ax_impl.mibs at module level during pytest collection — before any test file's path fixup runs. This causes:

ModuleNotFoundError: No module named 'sonic_ax_impl'

On bookworm the old setup.py test flow didn't hit this because the package remained installed. On trixie, the build switched to pip install/uninstall + pytest (slave.mk), and when the wheel cache misses, tests actually execute and fail.

Fix

Add a root conftest.py that inserts src/ into sys.path before pytest collection begins. This is harmless when sonic_ax_impl is already installed.

Motivation

Blocks sonic-net/sonic-buildimage#26551 (upgrade docker-snmp from bookworm to trixie).

Signed-off-by: Ying Xie ying.xie@microsoft.com

…tion

On trixie (bookworm+) builds, the wheel build flow runs:
  pip install '.[testing]' → pip uninstall asyncsnmp → python -m pytest

After pip uninstall, sonic_ax_impl is removed from site-packages.
Individual test files add src/ to sys.path, but
tests/mock_tables/dbconnector.py imports sonic_ax_impl.mibs at module
level during pytest collection — before any test file's sys.path fixup
runs. This causes ModuleNotFoundError on trixie where the asyncsnmp
wheel cache misses and tests actually execute.

Fix: add a root conftest.py that inserts src/ into sys.path before
collection begins. This is a no-op when sonic_ax_impl is already
installed.

Signed-off-by: Ying Xie <ying.xie@microsoft.com>
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

yxieca added a commit to yxieca/sonic-buildimage that referenced this pull request Apr 11, 2026
Migrate docker-snmp from Debian bookworm to trixie base:
- Update Dockerfile.j2 base image from bookworm to trixie
- Install snmp/snmpd from Debian repos via apt-get (on trixie,
  snmpd is no longer built from source per sonic-net#26357)
- Update rules/docker-snmp.mk references from BOOKWORM to TRIXIE
- No bookworm guards needed for SNMP/SNMPD dependencies: those
  variables are only defined on bookworm (snmpd.mk), so they
  resolve to empty on trixie — depending on empty is harmless
- Temporarily disable asyncsnmp unit tests (TEST=n) pending
  sonic-net/sonic-snmpagent#371 which fixes the sonic_ax_impl
  import error during pytest collection on trixie

Signed-off-by: Ying Xie <ying.xie@microsoft.com>
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.

2 participants