Skip to content
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

2.2.0 #11

Merged
merged 15 commits into from
Apr 9, 2024
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
.pytest_cache
*/**__pycache__
.idea
# file for test and debug
temp_test.py
build
pytest_analyzer.egg-info
pytest*.egg-info
dist
.venv*
pytest.ini
125 changes: 125 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
## 2.2.0 (2024-03-11)

### Feat

- Add TESTOMATIO_RUN to support test runs created on testomatio
- Add https://www.conventionalcommits.org/en/v1.0.0/ support

### Fix

- Fix syncing local test with testomatio that are imported in a custom folder (on testomatio end)
- Fix test run completion
- Fix to check testomatio session
- Allow all pytest hooks execution when running sync command that run before pytest_runtestloop (actual tests)
- Fix shared run reporting into new test run
- Fix/workarround of the incorreclty processed parameterised test on API
- Fix dot and space in parameterised test, fix project dependency

## 2.1.0 (2024-03-07)

### Feat

- Added support for `TESTOMATIO_TITLE`, `TESTOMATIO_SHARED_RUN` and `TESTOMATIO_LABEL`

## 2.0.0 (2024-03-05)

### Feat

- Align naming with Testomat.io branding
- add --directory option to import test into specific directory in testomat.io

## 1.7 (2024-02-26)

### Fix

- Fixes parameterized test sync and report

### 1.6.0 (2024-02-21)

### Feat

- Add helped to attach test artifacts
- Expose environment variables to provide access to cloud storage
- Update readme

### Fix

- Testomaito not longer supports nested test suites. Suites could be only in a folder.


### 1.5.0 (2024-02-12)

### Fix
- Fixes artifacts in fixtures lifecycle
- Earlier, artifacts added in pytest fixtures where skipped by analyser

### 1.4.0 (2024-02-06)

### Feat

- Adds `--create`, `--no-detached`, `--keep-structure`, `--no-empty`, for compatibility with original Testomatio check-tests
- Improves file update so it doesn't cause code style changes

### Fix
- Fixes artifacts uploads and test sync with Testomatio
- Fixes test id resolution when syncing local test with Testomatio
- Fixes test id when sending test into test run

### 1.3.0 (2023-12-06)

### Fix

- [issue 5](https://github.com/Ypurek/pytest-analyzer/issues/5) - connection issues not blocking test execution anymore

### 1.2.8 (2023-12-06)

### Fix

- [issue 4](https://github.com/Ypurek/pytest-analyzer/issues/4) - Analyzer's execution order

### 1.2.5 (2023-10-21)

### Feat

- added env variable `TESTOMATIO_RUNGROUP_TITLE` to group test runs

### Fix

- fixed serialization issue for update test status example

### 1.2.4 (2023-09-05)

### Fix

- improved parametrized tests reporting
- now parameters are passed to example attribute in the report

### 1.2.3 (2023-09-03)

### Fix

- fixed issue with test artifacts when no credentials provided, test artifacts will not be uploaded and no issue raised

### 1.2.0 (2023-08-20)

### Fix

- code refactored (Testomatio.io team review)
- simplified authentication. Only API key needed
- moved API key from pytest.ini to environment variable
- S3 credentials now read from testomat.io API, no local configuration needed
- Prettified test names in testomat.io

### 1.1.1 (2023-08-17)

### Feat

- added artifacts support (screenshots, logs) to test report

### 1.0.9 (2023-07-31)

### Feat
- first public release
- test analyzer able to sync tests with testomat.io
- test analyzer able to add test ids to tests
- test analyzer able to submit test results to testomat.io
73 changes: 8 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,70 +184,6 @@ def test_example():
| Debugging | parity | `pytest --testomatio debug` |


## Change log

### 2.1.0
- Added support for `TESTOMATIO_TITLE`, `TESTOMATIO_SHARED_RUN` and `TESTOMATIO_LABEL`

### 2.0.0 - Reunion
- Align naming with Testomat.io branding
- add --directory option to import test into specific directory in testomat.io

### 1.7.0 - Fixes parameterized test sync and report

### 1.6.0 - Fixes nested suites
- Testomaito not longer supports nested test suites. Suites could be only in a folder.
- Add helped to attach test artifacts
- Expose environment variables to provide access to cloud storage
- Update readme

### 1.5.0 - Fixes artifacts in fixtures lifecycle
- Earlier, artifacts added in pytest fixtures where scipped by analyser

### 1.4.0 - Fixes artifacts and test sync with Testomatio
- Fixes artifacts uploads
- Fixes test id resolution when syncing local test with Testomatio
- Fixes test id when sending test into test run
- Adds `--create`, `--no-detached`, `--keep-structure`, `--no-empty`, for compatibility with original Testomatio check-tests
- Improves file update so it doesn't cause code style changes

### 1.3.0 - added artifacts support connector
- [issue 5](https://github.com/Ypurek/pytest-analyzer/issues/5) - connection issues not blocking test execution anymore

### 1.2.8 - fixed issues
- [issue 4](https://github.com/Ypurek/pytest-analyzer/issues/4) - Analyzer's execution order

### 1.2.5 - fixed issues

- added env variable `TESTOMATIO_RUNGROUP_TITLE` to group test runs
- fixed serialization issue for update test status example

### 1.2.4 - improved parametrized tests reporting

- now parameters are passed to example attribute in the report

### 1.2.3 - fixed issue with test artifacts

- if no credentials provided, test artifacts will not be uploaded and no issue raised

### 1.2.0 - major update after testomat.io review

- code refactored
- simplified authentication. Only API key needed
- moved API key from pytest.ini to environment variable
- S3 credentials now read from testomat.io API, no local configuration needed
- Prettified test names in testomat.io

### 1.1.0 - added artifacts support connector

- there is possibility to add artifacts (screenshots, logs) to test report

### 1.0.9 - first public release

- test analyzer able to sync tests with testomat.io
- test analyzer able to add test ids to tests
- test analyzer able to submit test results to testomat.io

## Test
- import into empty project
- updated test - (resync)
Expand All @@ -258,4 +194,11 @@ def test_example():
## TODO
- Fix test duration
- Require more back references from testomatio
- pytest.skip should behave as @pytest.mark.skip
- pytest.skip should behave as @pytest.mark.skip
- Refactor test run and make run url available

## Contribution
1. `pip install -e .`
2. `cz commit`
3. `cz bump`
4. `git push remoteName branchName --tags`
14 changes: 11 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
[build-system]
requires = ["setuptools>=65.5.1", "requests>=2.29.0", "pytest<8.0.0,>=7.3.1", "boto3>=1.28.28", "libcst==1.1.0"]
requires = ["setuptools>=65.5.1", "requests>=2.29.0", "pytest<8.0.0,>=7.3.1", "boto3>=1.28.28", "libcst==1.1.0", "commitizen>=3.18.1"]
build-backend = "setuptools.build_meta"

[tool.setuptools.packages.find]
exclude = [".github", "tests"]


[tool.commitizen]
name = "cz_conventional_commits"
tag_format = "$version"
version_scheme = "pep440"
version_provider = "pep621"
update_changelog_on_bump = true
[project]
name = "pytestomatio"
version = "2.1.2"
version = "2.2.0"

dependencies = [
"requests>=2.29.0",
"pytest<8.0.0,>=7.3.1",
"boto3>=1.28.28",
"libcst==1.1.0"]
"libcst==1.1.0",
"commitizen>=3.18.1"]

authors = [
{ name = "Oleksii Ostapov" },
Expand Down
39 changes: 36 additions & 3 deletions pytestomatio/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from requests.exceptions import HTTPError, ConnectionError
import logging
from os.path import join, normpath
from os import getenv

from .testItem import TestItem

Expand Down Expand Up @@ -69,17 +70,46 @@ def get_tests(self, test_metadata: list[TestItem]) -> dict:

def create_test_run(self, title: str, group_title, env: str, label: str, shared_run: bool, parallel) -> dict | None:
request = {
"api_key": self.api_key,
"title": title,
"group_title": group_title,
"env": env,
"label": label,
"parallel": parallel,
"shared_run": shared_run,
}
filtered_request = {k: v for k, v in request.items() if v is not None}
print('create_test_run', filtered_request)
try:
response = self.session.post(f'{self.base_url}/api/reporter', json=filtered_request)
except ConnectionError:
log.error(f'Failed to connect to {self.base_url}')
return
except HTTPError:
log.error(f'Failed to connect to {self.base_url}')
return
except Exception as e:
log.error(f'Generic exception happened. Please report an issue. {e}')
return

if response.status_code == 200:
log.info(f'Test run created {response.json()["uid"]}')
return response.json()

def update_test_run(self, id: str, title: str, group_title, env: str, label: str, shared_run: bool, parallel) -> dict | None:
request = {
"api_key": self.api_key,
"title": title,
"group_title": group_title,
#"env": env, TODO: enabled when bug with 500 response fixed
#"label": label, TODO: enabled when bug with 500 response fixed
"parallel": parallel,
"shared_run": shared_run
}
filtered_request = {k: v for k, v in request.items() if v is not None}

try:
response = self.session.post(f'{self.base_url}/api/reporter?api_key={self.api_key}', json=filtered_request)
response = self.session.put(f'{self.base_url}/api/reporter/{id}', json=filtered_request)
except ConnectionError:
log.error(f'Failed to connect to {self.base_url}')
return
Expand All @@ -91,7 +121,7 @@ def create_test_run(self, title: str, group_title, env: str, label: str, shared_
return

if response.status_code == 200:
log.info(f'Test run created {response.json()["uid"]}')
log.info(f'Test run updated {response.json()["uid"]}')
return response.json()

def update_test_status(self, run_id: str,
Expand Down Expand Up @@ -138,10 +168,13 @@ def update_test_status(self, run_id: str,
if response.status_code == 200:
log.info('Test status updated')

# TODO: I guess this class should be just an API client and used within testRun (testRunConfig)
def finish_test_run(self, run_id: str) -> None:
is_parallel = getenv('TESTOMATIO_SHARED_RUN') in ['True', 'true', '1']
status_event = "finish_parallel" if is_parallel else 'finish'
try:
self.session.put(f'{self.base_url}/api/reporter/{run_id}?api_key={self.api_key}',
json={"status_event": "finish"})
json={"status_event": status_event})
except ConnectionError:
log.error(f'Failed to connect to {self.base_url}')
return
Expand Down
13 changes: 11 additions & 2 deletions pytestomatio/helper.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from os.path import basename
from pytest import Item
from .testomat_item import TestomatItem
from .testItem import TestItem
Expand Down Expand Up @@ -63,11 +64,19 @@ def add_and_enrich_tests(meta: list[TestItem], test_files: set,
tcm_test_data = parse_test_list(testomatio_tests)
for test in meta:
for tcm_test in tcm_test_data:
if test.resync_title == tcm_test.title and test.file_name == tcm_test.file_name:
if not tcm_test.file_name:
continue
# Test that are synced into user specified folder - might end up with altered file path in testomatio
# making file path not match between source code and testomatio
# to mitigate this we compare only file names, skipping the path
# while it works it might not be the most reliable approach
# however, the underlying issue is the ability to alter the file path in testomatio
# https://github.com/testomatio/check-tests?tab=readme-ov-file#import-into-a-specific-suite
if test.resync_title == tcm_test.title and basename(test.file_name) == basename(tcm_test.file_name):
test.id = tcm_test.id
tcm_test_data.remove(tcm_test)
break

mapping = get_test_mapping(meta)
for test_file in test_files:
update_tests(test_file, mapping, test_names, decorator_name)
update_tests(test_file, mapping, test_names, decorator_name)
Loading