From 001578534e4476da58c0902e3b8200c5033e71bb Mon Sep 17 00:00:00 2001 From: AenEnlil Date: Thu, 9 Oct 2025 17:53:23 +0300 Subject: [PATCH 1/3] implemented hook to exclude files by given pattern --- pytestomatio/main.py | 16 ++++++++++++++++ tests/test_main.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/pytestomatio/main.py b/pytestomatio/main.py index 2b0d4fc..ef5db2b 100644 --- a/pytestomatio/main.py +++ b/pytestomatio/main.py @@ -87,6 +87,22 @@ def pytest_configure(config: Config): # This ensures we only apply our OR logic after other filters have done their job. config.pluginmanager.register(TestomatioFilterPlugin(), "testomatio_filter_plugin") + +def pytest_ignore_collect(collection_path, path, config): + if config.getoption(testomatio) is None or config.getoption(testomatio) != 'report': + return + + exclude_patterns = os.environ.get('TESTOMATIO_EXCLUDE_FILES_FROM_REPORT_GLOB_PATTERN', None) + if not exclude_patterns: + return + + exclude_patterns = exclude_patterns.split(';') + relative_path = collection_path.relative_to(config.rootpath) + for pattern in exclude_patterns: + if pattern and relative_path.match(pattern): + return True + + @pytest.hookimpl(tryfirst=True) def pytest_collection_modifyitems(session: Session, config: Config, items: list[Item]) -> None: if config.getoption(testomatio) is None: diff --git a/tests/test_main.py b/tests/test_main.py index 5488177..08f045f 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,3 +1,5 @@ +from pathlib import Path + import pytest import os @@ -40,6 +42,45 @@ def test_pytest_collection_stores_original_items(self): assert mock_session._pytestomatio_original_collected_items == [] +@pytest.mark.smoke +class TestPytestIgnoreCollect: + """Tests for pytest_ignore_collect hook""" + + @pytest.fixture + def mock_config(self): + config = Mock() + config.getoption.return_value = 'report' + config.rootpath = 'temp/' + return config + + def test_ignores_by_extension(self, mock_config): + pattern = '**/*.py' + paths = [('directory/test_file.py', True), ('directory/file.py', True), ('new_dir/file.js', None)] + with patch.dict(os.environ, {'TESTOMATIO_EXCLUDE_FILES_FROM_REPORT_GLOB_PATTERN': pattern}, clear=True): + for path, expected_result in paths: + collect_path = Path(mock_config.rootpath + path) + result = main.pytest_ignore_collect(collect_path, collect_path, mock_config) + assert result is expected_result + + def test_ignores_by_name(self, mock_config): + pattern = '**/test_*.py' + paths = [('directory/test_file.py', True), ('directory/file.py', None), ('directory/file.js', None)] + with patch.dict(os.environ, {'TESTOMATIO_EXCLUDE_FILES_FROM_REPORT_GLOB_PATTERN': pattern}, clear=True): + for path, expected_result in paths: + collect_path = Path(mock_config.rootpath + path) + result = main.pytest_ignore_collect(collect_path, collect_path, mock_config) + assert result is expected_result + + def test_ignores_by_directory(self, mock_config): + pattern = '**/directory' + paths = [('directory/test_file.py', True), ('directory/file.py', True), ('new/file.js', None)] + with patch.dict(os.environ, {'TESTOMATIO_EXCLUDE_FILES_FROM_REPORT_GLOB_PATTERN': pattern}, clear=True): + for path, expected_result in paths: + collect_path = Path(mock_config.rootpath + path) + result = main.pytest_ignore_collect(collect_path, collect_path, mock_config) + assert result is expected_result + + @pytest.mark.smoke class TestPytestConfigure: """Tests for pytest_configure hook""" From 055dea9a05beda9029d5e9143df317ef7097fd01 Mon Sep 17 00:00:00 2001 From: AenEnlil Date: Thu, 9 Oct 2025 19:11:51 +0300 Subject: [PATCH 2/3] updated README.md --- README.md | 25 +++++++++++++------------ tests/test_main.py | 10 ---------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index b9ba012..5c731c1 100644 --- a/README.md +++ b/README.md @@ -186,19 +186,20 @@ You can use environment variable to control certain features of testomat.io #### Test Run configuration -| Env variable | What it does | Examples | -|--------------------------|----------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------| -| TESTOMATIO_TITLE | Name of a test run to create on testomat.io | TESTOMATIO_TITLE="Nightly Smoke Tests" pytest --testomatio report | -| TESTOMATIO_RUN_ID | Id of existing test run to use for sending test results to | TESTOMATIO_RUN_ID=98dfas0 pytest --testomatio report | -| TESTOMATIO_RUNGROUP_TITLE | Create a group (folder) for a test run. If group already exists, attach test run to it | TESTOMATIO_RUNGROUP_TITLE="Release 2.0" pytest --testomatio report | -| TESTOMATIO_ENV | Assign environment to a test run, env variant of **testRunEnv** option. Has a lower precedence than **testRunEnv** option. | TESTOMATIO_ENV="linux,chrome,1920x1080" pytest --testomatio report | -| TESTOMATIO_LABEL | Assign labels to a test run. Labels must exist in project and their scope must be enabled for runs | TESTOMATIO_LABEL="smoke,regression" pytest --testomatio report | -| TESTOMATIO_UPDATE_CODE | Send code of your test to Testomat.io on each run. If not enabled(default) assumes the code is pushed using **sync** command | TESTOMATIO_UPDATE_CODE=True pytest --testomatio report | -| TESTOMATIO_EXCLUDE_SKIPPED | Exclude skipped tests from the report | TESTOMATIO_EXCLUDE_SKIPPED=1 pytest --testomatio report | -| TESTOMATIO_PUBLISH | Publish run after reporting and provide a public URL | TESTOMATIO_PUBLISH=true pytest --testomatio report | -| TESTOMATIO_PROCEED | Do not finalize the run | TESTOMATIO_PROCEED=1 pytest --testomatio report | -| TESTOMATIO_SHARED_RUN | Report parallel execution to the same run matching it by title. If the run was created more than 20 minutes ago, a new run will be created instead. | TESTOMATIO_TITLE="Run1" TESTOMATIO_SHARED_RUN=1 pytest --testomatio report | +| Env variable | What it does | Examples | +|--------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------| +| TESTOMATIO_TITLE | Name of a test run to create on testomat.io | TESTOMATIO_TITLE="Nightly Smoke Tests" pytest --testomatio report | +| TESTOMATIO_RUN_ID | Id of existing test run to use for sending test results to | TESTOMATIO_RUN_ID=98dfas0 pytest --testomatio report | +| TESTOMATIO_RUNGROUP_TITLE | Create a group (folder) for a test run. If group already exists, attach test run to it | TESTOMATIO_RUNGROUP_TITLE="Release 2.0" pytest --testomatio report | +| TESTOMATIO_ENV | Assign environment to a test run, env variant of **testRunEnv** option. Has a lower precedence than **testRunEnv** option. | TESTOMATIO_ENV="linux,chrome,1920x1080" pytest --testomatio report | +| TESTOMATIO_LABEL | Assign labels to a test run. Labels must exist in project and their scope must be enabled for runs | TESTOMATIO_LABEL="smoke,regression" pytest --testomatio report | +| TESTOMATIO_UPDATE_CODE | Send code of your test to Testomat.io on each run. If not enabled(default) assumes the code is pushed using **sync** command | TESTOMATIO_UPDATE_CODE=True pytest --testomatio report | +| TESTOMATIO_EXCLUDE_SKIPPED | Exclude skipped tests from the report | TESTOMATIO_EXCLUDE_SKIPPED=1 pytest --testomatio report | +| TESTOMATIO_PUBLISH | Publish run after reporting and provide a public URL | TESTOMATIO_PUBLISH=true pytest --testomatio report | +| TESTOMATIO_PROCEED | Do not finalize the run | TESTOMATIO_PROCEED=1 pytest --testomatio report | +| TESTOMATIO_SHARED_RUN | Report parallel execution to the same run matching it by title. If the run was created more than 20 minutes ago, a new run will be created instead. | TESTOMATIO_TITLE="Run1" TESTOMATIO_SHARED_RUN=1 pytest --testomatio report | | TESTOMATIO_SHARED_RUN_TIMEOUT | Changes timeout of shared run. After timeout, shared run won`t accept other runs with same name, and new runs will be created. Timeout is set in minutes, default is 20 minutes. | TESTOMATIO_TITLE="Run1" TESTOMATIO_SHARED_RUN=1 TESTOMATIO_SHARED_RUN_TIMEOUT=10 pytest --testomatio report | +| TESTOMATIO_EXCLUDE_FILES_FROM_REPORT_GLOB_PATTERN | Excludes tests from report using glob patterns. You can specify multiple patterns using **;** as separator | TESTOMATIO_EXCLUDE_FILES_FROM_REPORT_GLOB_PATTERN="**/*_auth.py;directory" pytest --testomatio report | #### S3 Bucket configuration diff --git a/tests/test_main.py b/tests/test_main.py index 08f045f..eb2705d 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -71,16 +71,6 @@ def test_ignores_by_name(self, mock_config): result = main.pytest_ignore_collect(collect_path, collect_path, mock_config) assert result is expected_result - def test_ignores_by_directory(self, mock_config): - pattern = '**/directory' - paths = [('directory/test_file.py', True), ('directory/file.py', True), ('new/file.js', None)] - with patch.dict(os.environ, {'TESTOMATIO_EXCLUDE_FILES_FROM_REPORT_GLOB_PATTERN': pattern}, clear=True): - for path, expected_result in paths: - collect_path = Path(mock_config.rootpath + path) - result = main.pytest_ignore_collect(collect_path, collect_path, mock_config) - assert result is expected_result - - @pytest.mark.smoke class TestPytestConfigure: """Tests for pytest_configure hook""" From 2c7d891d1443395402cf63292b78fa27cc53a989 Mon Sep 17 00:00:00 2001 From: AenEnlil Date: Thu, 9 Oct 2025 19:22:23 +0300 Subject: [PATCH 3/3] bump: version 2.10.2 -> 2.10.3b4 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 5cae11c..9b0b356 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ version_provider = "pep621" update_changelog_on_bump = false [project] name = "pytestomatio" -version = "2.10.2" +version = "2.10.3b4" dependencies = [