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

Refactor nox to separate integration tests #2950

Merged
merged 35 commits into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
91f47a1
Split tests on nox
patrick91 Jul 14, 2023
0d1db5d
Fix marker
patrick91 Jul 14, 2023
780fd75
Improve how we skip tests
patrick91 Jul 14, 2023
3eaa060
Make dependencies not required
patrick91 Jul 14, 2023
7d3c067
More ignores and import fixes
patrick91 Jul 14, 2023
02ddd37
More import skips
patrick91 Jul 14, 2023
7f7af4d
Remove aiohttp dep in tests
patrick91 Jul 14, 2023
1ded981
Fix
patrick91 Jul 14, 2023
279878f
Remove more imports
patrick91 Jul 14, 2023
3396022
More imports
patrick91 Jul 14, 2023
b161dff
One more import
patrick91 Jul 14, 2023
eda70bf
More skips
patrick91 Jul 14, 2023
c3d356f
Older pydantic when using starlite
patrick91 Jul 14, 2023
f26b1a3
Missing dep
patrick91 Jul 14, 2023
64f63f7
Missing dep
patrick91 Jul 14, 2023
9cfc1f7
Missing deps
patrick91 Jul 14, 2023
4638fd9
cli tests
patrick91 Jul 14, 2023
b082935
Merge branch 'main' into split-tests
patrick91 Jul 14, 2023
8264958
Merge branch 'main' into split-tests
patrick91 Jul 15, 2023
3734436
Fix federation
patrick91 Jul 15, 2023
9e37146
TMP disable cache
patrick91 Jul 15, 2023
37beab3
Reskip
patrick91 Jul 15, 2023
dab4f38
Merge branch 'main' into split-tests
patrick91 Jul 16, 2023
8241377
Reenable ws tests
patrick91 Jul 16, 2023
4de3c80
Fix more tests
patrick91 Jul 16, 2023
26e7b6c
Add coverage for tests
patrick91 Jul 16, 2023
8ec9096
Fix import path
patrick91 Jul 16, 2023
fdab0ff
Fix test
patrick91 Jul 16, 2023
7e1d5d2
Fix markers
patrick91 Jul 16, 2023
6155ea4
Test fix
patrick91 Jul 16, 2023
cb7efcf
Fix pydantic tests
patrick91 Jul 16, 2023
35d9e86
Remove unused fixtures
patrick91 Jul 16, 2023
82cd6c8
Run windows with poetry
patrick91 Jul 16, 2023
6de608c
Remove use
patrick91 Jul 16, 2023
f516f2e
Fix command
patrick91 Jul 16, 2023
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
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ignore_errors = True

omit =
./.venv/**
./tests/*
noxfile.py

[html]
directory = coverage_html_report
43 changes: 24 additions & 19 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ jobs:
- name: coverage xml
run: coverage xml -i
if: ${{ always() }}

- uses: codecov/codecov-action@v3
if: ${{ always() }}
with:
Expand Down Expand Up @@ -148,25 +149,29 @@ jobs:

steps:
- uses: actions/checkout@v3
- uses: wntrblm/nox@main
- run: pipx install poetry
- run: pipx install coverage
- uses: actions/setup-python@v4
id: setup-python
with:
python-versions: "3.7, 3.8, 3.9, 3.10, 3.11"
python-version: "3.11"
cache: "poetry"

- name: Pip and nox cache
id: cache
uses: actions/cache@v3
with:
path: |
~/.cache
~/.nox
.nox
key:
${{ runner.os }}-nox-windows-${{ hashFiles('**/poetry.lock') }}-${{
hashFiles('**/noxfile.py') }}
restore-keys: |
${{ runner.os }}-nox-windows
${{ runner.os }}-nox-
- run: poetry install --with integrations
if: steps.setup-python.outputs.cache-hit != 'true'

- run: pipx install poetry
- run: pipx inject nox nox-poetry
- run: nox -r -s "Tests" -p 3.11
# we use poetry directly instead of nox since we want to
# test all integrations at once on windows
- run: |
poetry run pytest --cov=. --cov-append --cov-report=xml -n auto --showlocals -vv

- name: coverage xml
run: coverage xml -i
if: ${{ always() }}

- uses: codecov/codecov-action@v3
if: ${{ always() }}
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
verbose: true
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Now, you will need to install the required dependencies for Strawberry and be su
that the current tests are passing on your machine:

```shell
$ poetry install
$ poetry install --with integrations
$ poetry run pytest tests -n auto
$ poetry run mypy
```
Expand Down
2 changes: 1 addition & 1 deletion federation-compatibility/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ COPY pyproject.toml ./
COPY poetry.lock ./
COPY README.md ./

RUN poetry install
RUN poetry install --with integrations

COPY federation-compatibility/schema.py ./

Expand Down
156 changes: 92 additions & 64 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,55 @@
import nox
from nox_poetry import Session, session

nox.options.reuse_existing_virtualenvs = True
nox.options.error_on_external_run = True

PYTHON_VERSIONS = ["3.11", "3.10", "3.9", "3.8", "3.7"]


COMMON_PYTEST_OPTIONS = [
patrick91 marked this conversation as resolved.
Show resolved Hide resolved
"--cov=.",
"--cov-append",
"--cov-report=xml",
"-n",
"auto",
"--showlocals",
"-vv",
"--ignore=tests/mypy",
"--ignore=tests/pyright",
"--ignore=tests/cli",
# TODO: reintroduce this in its own test session
"--ignore=tests/experimental/pydantic",
]

INTEGRATIONS = [
"asgi",
"aiohttp",
"chalice",
"channels",
"django",
"fastapi",
"flask",
"sanic",
"starlite",
"pydantic",
]


@session(python=PYTHON_VERSIONS, name="Tests", tags=["tests"])
def tests(session: Session) -> None:
session.run_always("poetry", "install", external=True)

markers = (
["-m", f"not {integration}", f"--ignore=tests/{integration}"]
for integration in INTEGRATIONS
)
markers = [item for sublist in markers for item in sublist]

session.run(
"pytest",
"--cov=strawberry",
"--cov-append",
"--cov-report=xml",
"-n",
"auto",
"--showlocals",
"-vv",
"-m",
"not starlette",
"-m",
"not django",
"-m",
"not starlite",
"-m",
"not pydantic",
"--ignore=tests/mypy",
"--ignore=tests/pyright",
*COMMON_PYTEST_OPTIONS,
*markers,
)


Expand All @@ -36,19 +59,9 @@ def tests_django(session: Session, django: str) -> None:
session.run_always("poetry", "install", external=True)

session._session.install(f"django~={django}") # type: ignore
session._session.install("pytest-django") # type: ignore

session.run(
"pytest",
"--cov=strawberry",
"--cov-append",
"--cov-report=xml",
"-n",
"auto",
"--showlocals",
"-vv",
"-m",
"django",
)
session.run("pytest", *COMMON_PYTEST_OPTIONS, "-m", "django")


@session(python=["3.11"], name="Starlette tests", tags=["tests"])
Expand All @@ -58,36 +71,38 @@ def tests_starlette(session: Session, starlette: str) -> None:

session._session.install(f"starlette=={starlette}") # type: ignore

session.run(
"pytest",
"--cov=strawberry",
"--cov-append",
"--cov-report=xml",
"-n",
"auto",
"--showlocals",
"-vv",
"-m",
"starlette",
)
session.run("pytest", *COMMON_PYTEST_OPTIONS, "-m", "asgi")


@session(python=["3.11"], name="Litestar tests", tags=["tests"])
def tests_litestar(session: Session) -> None:
@session(python=["3.11"], name="Test integrations", tags=["tests"])
@nox.parametrize(
"integration",
[
"aiohttp",
"chalice",
"channels",
"fastapi",
"flask",
"sanic",
"starlite",
],
)
def tests_integrations(session: Session, integration: str) -> None:
session.run_always("poetry", "install", external=True)

session.run(
"pytest",
"--cov=strawberry",
"--cov-append",
"--cov-report=xml",
"-n",
"auto",
"--showlocals",
"-vv",
"-m",
"starlite",
)
session._session.install(integration) # type: ignore

if integration == "aiohttp":
session._session.install("pytest-aiohttp") # type: ignore
elif integration == "flask":
session._session.install("pytest-flask") # type: ignore
elif integration == "channels":
session._session.install("pytest-django") # type: ignore
session._session.install("daphne") # type: ignore
elif integration == "starlite":
session._session.install("pydantic<2.0") # type: ignore

session.run("pytest", *COMMON_PYTEST_OPTIONS, "-m", integration)


@session(python=["3.11"], name="Pydantic tests", tags=["tests"])
Expand All @@ -100,25 +115,21 @@ def test_pydantic(session: Session, pydantic: str) -> None:

session.run(
"pytest",
"--cov=strawberry",
"--cov=.",
"--cov-append",
"--cov-report=xml",
"-n",
"auto",
"--showlocals",
"-vv",
"-m",
"pydantic",
)


@session(python=PYTHON_VERSIONS, name="Mypy tests")
def tests_mypy(session: Session) -> None:
session.run_always("poetry", "install", external=True)
session.run_always("poetry", "install", "--with", "integrations", external=True)

session.run(
"pytest",
"--cov=strawberry",
"--cov=.",
"--cov-append",
"--cov-report=xml",
"tests/mypy",
Expand All @@ -133,7 +144,7 @@ def tests_pyright(session: Session) -> None:

session.run(
"pytest",
"--cov=strawberry",
"--cov=.",
"--cov-append",
"--cov-report=xml",
"tests/pyright",
Expand All @@ -143,6 +154,23 @@ def tests_pyright(session: Session) -> None:

@session(name="Mypy", tags=["lint"])
def mypy(session: Session) -> None:
session.run_always("poetry", "install", external=True)
session.run_always("poetry", "install", "--with", "integrations", external=True)

session.run("mypy", "--config-file", "mypy.ini")


@session(python=PYTHON_VERSIONS, name="CLI tests", tags=["tests"])
def tests_cli(session: Session) -> None:
session.run_always("poetry", "install", external=True)

session._session.install("uvicorn") # type: ignore
session._session.install("starlette") # type: ignore

session.run(
"pytest",
"--cov=.",
"--cov-append",
"--cov-report=xml",
"tests/cli",
"-vv",
)
Loading
Loading