From 6395ecec756433194c05d34af490315b35dddafa Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Tue, 21 Sep 2021 10:40:56 +0300 Subject: [PATCH] Test conditional collection on PyPy and CPython --- .github/workflows/examples.yml | 12 ++++++++---- examples/adhoc-layout/example/__init__.py | 13 +++++++++++-- examples/adhoc-layout/tox.ini | 6 +++--- examples/src-layout/src/example/__init__.py | 13 +++++++++++-- examples/src-layout/tox.ini | 6 +++--- 5 files changed, 36 insertions(+), 14 deletions(-) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 5835c173..dbd62a6c 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -11,18 +11,22 @@ jobs: strategy: fail-fast: false matrix: + python-version: ["pypy-3.7", "3.9"] target: [ "src-layout", "adhoc-layout", ] - + include: + # Add new helper variables to existing jobs + - {python-version: "pypy-3.7", tox-python-version: "pypy3"} + - {python-version: "3.9", tox-python-version: "py39"} steps: - uses: actions/checkout@v2 - - name: Set up Python + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: - python-version: 3.9 + python-version: ${{ matrix.python-version }} - name: Cache uses: actions/cache@v2 @@ -42,4 +46,4 @@ jobs: - name: Examples run: | cd examples/${{ matrix.target }} - tox -v + tox -v -e ${{ matrix.tox-python-version }} diff --git a/examples/adhoc-layout/example/__init__.py b/examples/adhoc-layout/example/__init__.py index 4693ad3c..684905a1 100644 --- a/examples/adhoc-layout/example/__init__.py +++ b/examples/adhoc-layout/example/__init__.py @@ -1,2 +1,11 @@ -def add(a, b): - return a + b +import platform + +# test merging multiple tox runs with a platform +# based branch +if platform.python_implementation() == "PyPy": + def add(a, b): + return a + b + +else: + def add(a, b): + return a + b diff --git a/examples/adhoc-layout/tox.ini b/examples/adhoc-layout/tox.ini index 7b6f7c43..e855c315 100644 --- a/examples/adhoc-layout/tox.ini +++ b/examples/adhoc-layout/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py38,report +envlist = pypy3,py39,report [tool:pytest] addopts = @@ -7,7 +7,7 @@ addopts = [testenv] setenv = - py38: COVERAGE_FILE = .coverage.{envname} + py{py3,39}: COVERAGE_FILE = .coverage.{envname} commands = pytest --cov --cov-config={toxinidir}/.coveragerc {posargs:-vv} deps = pytest @@ -19,7 +19,7 @@ deps = ../.. depends = - report: py38 + report: pypy3,py39 # note that this is necessary to prevent the tests importing the code from your badly laid project changedir = tests diff --git a/examples/src-layout/src/example/__init__.py b/examples/src-layout/src/example/__init__.py index 4693ad3c..684905a1 100644 --- a/examples/src-layout/src/example/__init__.py +++ b/examples/src-layout/src/example/__init__.py @@ -1,2 +1,11 @@ -def add(a, b): - return a + b +import platform + +# test merging multiple tox runs with a platform +# based branch +if platform.python_implementation() == "PyPy": + def add(a, b): + return a + b + +else: + def add(a, b): + return a + b diff --git a/examples/src-layout/tox.ini b/examples/src-layout/tox.ini index 5a2083c9..94b72730 100644 --- a/examples/src-layout/tox.ini +++ b/examples/src-layout/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py38,report +envlist = pypy3,py39,report [tool:pytest] testpaths = tests @@ -8,7 +8,7 @@ addopts = [testenv] setenv = - py38: COVERAGE_FILE = .coverage.{envname} + py{py3,39}: COVERAGE_FILE = .coverage.{envname} commands = pytest --cov {posargs:-vv} deps = pytest @@ -20,7 +20,7 @@ deps = ../.. depends = - report: py38 + report: pypy3,py39 [testenv:report] skip_install = true