Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ You can use environment variable to control certain features of testomat.io
| TESTOMATIO_STACK_PASSED | Enables logs for passed tests. Disabled by default. | TESTOMATIO_STACK_PASSED=true 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 |
| TESTOMATIO_CREATE | Create test which are not yet exist in a project | TESTOMATIO_CREATE=1 pytest --testomatio report |
| TESTOMATIO_WORKDIR | Specify a custom working directory for relative file paths in test reports. When tests are created with **TESTOMATIO_CREATE=1**, file paths will be relative to this directory. | TESTOMATIO_WORKDIR=new_dir pytest --testomatio report |
| TESTOMATIO_DISABLE_BATCH_UPLOAD | Disables batch uploading and uploads each test result one by one. | TESTOMATIO_DISABLE_BATCH_UPLOAD=True pytest --testomatio report |
Expand Down
16 changes: 16 additions & 0 deletions pytestomatio/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,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, 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:
Expand Down
31 changes: 31 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

import pytest
import os

Expand Down Expand Up @@ -40,6 +42,35 @@ 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, 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, mock_config)
assert result is expected_result

@pytest.mark.smoke
class TestPytestConfigure:
"""Tests for pytest_configure hook"""
Expand Down
Loading