Skip to content
Open
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
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ version_provider = "pep621"
update_changelog_on_bump = false
[project]
name = "pytestomatio"
version = "2.10.2"
version = "2.10.3b4"


dependencies = [
Expand Down
16 changes: 16 additions & 0 deletions pytestomatio/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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, 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

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