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
12 changes: 10 additions & 2 deletions .github/workflows/pr-build-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,22 @@ jobs:
run: docker compose build app_test

- name: "Create environment file"
run: touch .env
run: env | grep -E '^MPT_' > .env
env:
RP_ENDPOINT: ${{ secrets.RP_ENDPOINT }}
RP_API_KEY: ${{ secrets.RP_API_KEY }}
MPT_API_BASE_URL: ${{ secrets.MPT_API_BASE_URL }}
MPT_API_TOKEN: ${{ secrets.MPT_API_TOKEN }}

- name: "Run validation & test"
run: docker compose run --service-ports app_test

- name: "Run E2E test"
run: docker compose run --service-ports -e MPT_API_BASE_URL=$MPT_API_BASE_URL -e MPT_API_TOKEN=$MPT_API_TOKEN e2e
run: docker compose run --service-ports app_test bash -c "pytest -p no:randomly --no-cov --reportportal --rp-launch=$RP_LAUNCH --rp-api-key=$RP_API_KEY --rp-endpoint=$RP_ENDPOINT --junitxml=e2e-report.xml tests/e2e"
env:
RP_LAUNCH: github-e2e-test
RP_ENDPOINT: ${{ secrets.RP_ENDPOINT }}
RP_API_KEY: ${{ secrets.RP_API_KEY }}
MPT_API_BASE_URL: ${{ secrets.MPT_API_BASE_URL }}
MPT_API_TOKEN: ${{ secrets.MPT_API_TOKEN }}

Expand Down
39 changes: 9 additions & 30 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,11 @@ services:
env_file:
- .env

app_test:
container_name: mpt_api_client_test
build:
context: .
dockerfile: dev.Dockerfile
working_dir: /mpt_api_client
command: bash -c "ruff format --check . && ruff check . && flake8 . && mypy . && uv lock --check && pytest"
volumes:
- .:/mpt_api_client

bash:
container_name: mpt_api_client_bash
bash: &dev_base
image: mpt_api_client_dev
build:
context: .
dockerfile: dev.Dockerfile
command: bash
working_dir: /mpt_api_client
stdin_open: true
tty: true
Expand All @@ -36,24 +25,14 @@ services:
env_file:
- .env

app_test:
<<: *dev_base
command: bash -c "ruff format --check . && ruff check . && flake8 . && mypy . && uv lock --check && pytest tests/unit"

format:
container_name: mpt_api_client_format
build:
context: .
dockerfile: dev.Dockerfile
working_dir: /mpt_api_client
<<: *dev_base
command: bash -c "ruff check . --select I --fix && ruff format ."
volumes:
- .:/mpt_api_client

e2e:
container_name: mpt_api_client_test
build:
context: .
dockerfile: dev.Dockerfile
working_dir: /mpt_api_client
command: bash -c "pytest -m e2e -p no:randomly --junitxml=e2e-report.xml"
volumes:
- .:/mpt_api_client
env_file:
- .env
<<: *dev_base
command: bash -c "pytest -p no:randomly --junitxml=e2e-report.xml tests/e2e"
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dev = [
"pytest-deadfixtures==2.2.*",
"pytest-mock==3.14.*",
"pytest-randomly==3.16.*",
"pytest-reportportal>=5.5.2",
"pytest-rerunfailures>=16.1",
"pytest-xdist==3.6.*",
"responses==0.25.*",
Expand All @@ -59,17 +60,15 @@ build-backend = "hatchling.build"
[tool.pytest.ini_options]
testpaths = "tests"
pythonpath = "."
addopts = "--cov=mpt_api_client --cov-report=term-missing --cov-report=html --cov-report=xml --import-mode=importlib -m 'not e2e'"
addopts = "--cov=mpt_api_client --cov-report=term-missing --cov-report=html --cov-report=xml --import-mode=importlib"
log_cli = false
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"
filterwarnings = [
"ignore:Support for class-based `config` is deprecated:DeprecationWarning",
"ignore:pkg_resources is deprecated as an API:DeprecationWarning",
]
markers = [
"e2e: marks tests as e2e"
]
rp_project = "mpt-api-python-client"

[tool.coverage.run]
branch = true
Expand Down
10 changes: 10 additions & 0 deletions tests/e2e/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import logging
import os

import pytest
from reportportal_client import RPLogger

from mpt_api_client import MPTClient

Expand All @@ -18,3 +20,11 @@ def base_url():
@pytest.fixture
def mpt_client(api_token, base_url):
return MPTClient.from_config(api_token=api_token, base_url=base_url)


@pytest.fixture(scope="session")
def rp_logger():
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logging.setLoggerClass(RPLogger)
return logger
9 changes: 4 additions & 5 deletions tests/e2e/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@


@pytest.mark.flaky(reruns=5, reruns_delay=0.01) # noqa: WPS432
@pytest.mark.e2e
def test_example():
assert random.choice([True, False]) # noqa: S311
def test_example(rp_logger):
choice = random.choice([True, False]) # noqa: S311
rp_logger.info("Choice: %s", choice)
assert choice is True


@pytest.mark.flaky
@pytest.mark.e2e
def test_unauthorised(base_url):
client = MPTClient.from_config(api_token="TKN-invalid", base_url=base_url) # noqa: S106

Expand All @@ -22,7 +22,6 @@ def test_unauthorised(base_url):


@pytest.mark.flaky
@pytest.mark.e2e
def test_access(mpt_client):
product = mpt_client.catalog.products.get("PRD-1975-5250")
assert product.id == "PRD-1975-5250"
Expand Down
Loading