Skip to content

twister: Add configuration reader to pytest-twister-harness #94301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fundakol
Copy link
Contributor

@fundakol fundakol commented Aug 9, 2025

Added a class twister_harness.helpers.config_reader.ConfigReader that helps to read Kconfigs from a configuration file.

Added pytest fixture config_reader that provides a ConfigReader instance for reading configuration files.

This fixture allows tests to easily create a ConfigReader object by passing
the path to a configuration file. The ConfigReader reads the file and
provides a method to access the configuration data.

Example:

def test_config_value(config_reader):
    config = config_reader("pm.config")
    assert config.read("some_key") == "expected_value"

@zephyrbot zephyrbot added the area: Twister Twister label Aug 9, 2025
@fundakol fundakol force-pushed the twister-pytest-improve-config-reader branch 2 times, most recently from 0dddba5 to e5301ed Compare August 9, 2025 19:59
Copy link
Contributor

@gchwier gchwier left a comment

Choose a reason for hiding this comment

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

Thanks for adding it! looks great, only minor comments

@fundakol fundakol force-pushed the twister-pytest-improve-config-reader branch from e5301ed to 73df250 Compare August 12, 2025 07:28
@hakehuang
Copy link
Contributor

hakehuang commented Aug 12, 2025

def test_config_value(config_reader):
    config = config_reader("pm.config")
    assert config.read("some_key") == "expected_value"

can we add more support to reader from and environ variable such as

config_path = os.enviroment["CONFIG_PATH"]
config = config_reader(f"{config_path}/pm.config")

gchwier
gchwier previously approved these changes Aug 12, 2025
@gchwier
Copy link
Contributor

gchwier commented Aug 12, 2025

def test_config_value(config_reader):
    config = config_reader("pm.config")
    assert config.read("some_key") == "expected_value"

can we add more support to reader from and environ variable such as

config_path = os.enviroment["CONFIG_PATH"]
config = config_reader(f"{config_path}/pm.config")

This is example of test implementation, so you can provide the path as you want.
When using dut fixture, the easiest way is to take build dir from dut:

sysbuild_config = config_reader(dut.device_config.build_dir / "zephyr" / ".config")
app_config = config_reader(dut.device_config.app_build_dir / "zephyr" / ".config")
mcuboot_config = config_reader(dut.device_config.build_dir / "mcuboot" / "zephyr" / ".config")
cmake_cache = config_reader(dut.device_config.app_build_dir / "CMakeCache.txt")

or just take the path from env variable

Added a class that helps to read Kconfigs from a configuration file.

Signed-off-by: Lukasz Fundakowski <[email protected]>
@fundakol fundakol force-pushed the twister-pytest-improve-config-reader branch from 73df250 to 7086eaf Compare August 12, 2025 09:26
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants