Skip to content

Commit

Permalink
Allow to run directly with pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeut committed Nov 17, 2019
1 parent 56e244f commit 8df156e
Show file tree
Hide file tree
Showing 24 changed files with 56 additions and 132 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
command: bash .circleci/prepare.sh
- run:
name: Test.
command: venv/bin/python ./bin/run_tests.py
command: venv/bin/python -m pytest

osx-python3:
macos:
Expand All @@ -29,7 +29,7 @@ jobs:
command: bash .circleci/prepare.sh
- run:
name: Test.
command: venv/bin/python ./bin/run_tests.py
command: venv/bin/python -m pytest

linux-python2:
docker:
Expand All @@ -45,7 +45,7 @@ jobs:
command: bash .circleci/prepare.sh
- run:
name: Test.
command: venv/bin/python ./bin/run_tests.py
command: venv/bin/python -m pytest

linux-python3:
docker:
Expand All @@ -61,7 +61,7 @@ jobs:
command: bash .circleci/prepare.sh
- run:
name: Test.
command: venv/bin/python ./bin/run_tests.py
command: venv/bin/python -m pytest

workflows:
version: 2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ nosetests.xml
coverage.xml
*,cover
.hypothesis/
.pytest_cache

# Translations
*.mo
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ matrix:
install:
- C:\\Python35\\python -m pip install -r requirements-dev.txt
script:
- C:\\Python35\\python ./bin/run_tests.py
- C:\\Python35\\python -m pytest

install: $PYTHON -m pip install -r requirements-dev.txt

script: $PYTHON ./bin/run_tests.py
script: $PYTHON -m pytest
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ build_script:
- sh: "${HOME}/.localpython3.7.4/bin/python3 -m pip install -r requirements-dev.txt"
# the '-u' flag is required so the output is in the correct order.
# See https://github.com/joerick/cibuildwheel/pull/24 for more info.
- cmd: "C:\\Python27\\python.exe -u ./bin/run_tests.py"
- sh: "${HOME}/.localpython3.7.4/bin/python3 ./bin/run_tests.py"
- cmd: "C:\\Python27\\python.exe -u -m pytest"
- sh: "${HOME}/.localpython3.7.4/bin/python3 -m pytest"
10 changes: 6 additions & 4 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ jobs:
versionSpec: '3.8'
- bash: |
python -m pip install -r requirements-dev.txt
python ./bin/run_tests.py
python -m pip install pytest-azurepipelines
python -m pytest
- job: macos
pool: {vmImage: 'macOS-10.13'}
Expand All @@ -17,7 +18,8 @@ jobs:
versionSpec: '3.8'
- bash: |
python -m pip install -r requirements-dev.txt
python ./bin/run_tests.py
python -m pip install pytest-azurepipelines
python -m pytest
- job: windows
pool: {vmImage: 'vs2017-win2016'}
Expand All @@ -29,5 +31,5 @@ jobs:
displayName: Install Visual C++ for Python 2.7
- bash: |
python -m pip install -r requirements-dev.txt
python ./bin/run_tests.py
python -m pip install pytest-azurepipelines
python -m pytest
2 changes: 1 addition & 1 deletion bin/dev_run_test
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
cd "$(dirname "$0")"
cd ..

CIBW_PLATFORM=linux ./bin/run_test.py $1
CIBW_PLATFORM=linux python -m pytest -vv $1
38 changes: 0 additions & 38 deletions bin/run_test.py

This file was deleted.

29 changes: 0 additions & 29 deletions bin/run_tests.py

This file was deleted.

1 change: 1 addition & 0 deletions cibuildwheel/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def main():
platform = args.platform
else:
ci = strtobool(os.environ.get('CI', 'false')) or 'BITRISE_BUILD_NUMBER' in os.environ or 'AZURE_HTTP_USER_AGENT' in os.environ
platform = None
if ci:
if sys.platform.startswith('linux'):
platform = 'linux'
Expand Down
5 changes: 5 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[pytest]
addopts = -vv
testpaths = unit_test test
norecursedirs = spamtest
python_files = test_*.py *_test.py cibw_test_*.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import os
from utils import utils


PROJECT_DIR = os.path.dirname(__file__)


def test(utils):
# build the wheels
utils.cibuildwheel_run(PROJECT_DIR)
utils.cibuildwheel_run()

# check that the expected wheels are produced
expected_wheels = utils.expected_wheels('spam', '0.1.0')
Expand All @@ -23,5 +19,5 @@ def test_build_identifiers(utils):
# the expected wheels
expected_wheels = [w for w in utils.expected_wheels('spam', '0.1.0')
if not '-manylinux' in w or '-manylinux1' in w]
build_identifiers = utils.cibuildwheel_get_build_identifiers(PROJECT_DIR)
build_identifiers = utils.cibuildwheel_get_build_identifiers()
assert len(expected_wheels) == len(build_identifiers)
18 changes: 7 additions & 11 deletions test/02_test/cibuildwheel_test.py → test/02_test/cibw_test_02.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import os, subprocess
import pytest
from utils import utils


PROJECT_DIR = os.path.dirname(__file__)


def test(utils):
# build and test the wheels
utils.cibuildwheel_run(PROJECT_DIR, add_env={
utils.cibuildwheel_run(add_env={
'CIBW_TEST_REQUIRES': 'nose',
# the 'false ||' bit is to ensure this command runs in a shell on
# mac/linux.
'CIBW_TEST_COMMAND': 'false || nosetests {project}/test',
'CIBW_TEST_COMMAND_WINDOWS': 'nosetests {project}/test',
'CIBW_TEST_COMMAND': 'false || nosetests {project}/spamtest',
'CIBW_TEST_COMMAND_WINDOWS': 'nosetests {project}/spamtest',
})

# also check that we got the right wheels
Expand All @@ -24,12 +20,12 @@ def test(utils):

def test_extras_require(utils):
# build and test the wheels
utils.cibuildwheel_run(PROJECT_DIR, add_env={
utils.cibuildwheel_run(add_env={
'CIBW_TEST_EXTRAS': 'test',
# the 'false ||' bit is to ensure this command runs in a shell on
# mac/linux.
'CIBW_TEST_COMMAND': 'false || nosetests {project}/test',
'CIBW_TEST_COMMAND_WINDOWS': 'nosetests {project}/test',
'CIBW_TEST_COMMAND': 'false || nosetests {project}/spamtest',
'CIBW_TEST_COMMAND_WINDOWS': 'nosetests {project}/spamtest',
})

# also check that we got the right wheels
Expand All @@ -41,7 +37,7 @@ def test_extras_require(utils):
def test_failing_test(utils):
'''Ensure a failing test causes cibuildwheel to error out and exit'''
with pytest.raises(subprocess.CalledProcessError):
utils.cibuildwheel_run(PROJECT_DIR, add_env={
utils.cibuildwheel_run(add_env={
'CIBW_TEST_COMMAND': 'false',
# manylinux1 has a version of bash that's been shown to have
# problems with this, so let's check that.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import os
from utils import utils


PROJECT_DIR = os.path.dirname(__file__)


def test(utils):
# build the wheels
utils.cibuildwheel_run(PROJECT_DIR, add_env={
utils.cibuildwheel_run(add_env={
# write python version information to a temporary file, this is
# checked in setup.py
'CIBW_BEFORE_BUILD': '''python -c "import sys; open('/tmp/pythonversion.txt', 'w').write(sys.version)" && python -c "import sys; open('/tmp/pythonexecutable.txt', 'w').write(sys.executable)"''',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import os
from utils import utils


PROJECT_DIR = os.path.dirname(__file__)


def test(utils):
# build the wheels
utils.cibuildwheel_run(PROJECT_DIR, add_env={
utils.cibuildwheel_run(add_env={
'CIBW_BUILD': 'cp3?-*',
'CIBW_SKIP': 'cp37-*',
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import os
from utils import utils


PROJECT_DIR = os.path.dirname(__file__)


def test(utils):
# write some information into the CIBW_ENVIRONMENT, for expansion and
# insertion into the environment by cibuildwheel. This is checked
# in setup.py
utils.cibuildwheel_run(PROJECT_DIR, add_env={
utils.cibuildwheel_run(add_env={
'CIBW_ENVIRONMENT': '''CIBW_TEST_VAR="a b c" CIBW_TEST_VAR_2=1 CIBW_TEST_VAR_3="$(echo 'test string 3')" PATH=$PATH:/opt/cibw_test_path''',
'CIBW_ENVIRONMENT_WINDOWS': '''CIBW_TEST_VAR="a b c" CIBW_TEST_VAR_2=1 CIBW_TEST_VAR_3="$(echo 'test string 3')" PATH="$PATH;/opt/cibw_test_path"''',
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import os, pytest
from utils import utils


PROJECT_DIR = os.path.dirname(__file__)


def test(utils):
if utils.platform != 'linux':
pytest.skip('the test is only relevant to the linux build')

utils.cibuildwheel_run(PROJECT_DIR, add_env={
utils.cibuildwheel_run(add_env={
'CIBW_MANYLINUX_X86_64_IMAGE': 'dockcross/manylinux2010-x64',
'CIBW_MANYLINUX_I686_IMAGE': 'dockcross/manylinux1-x86',
'CIBW_BEFORE_BUILD': '/opt/python/cp36-cp36m/bin/pip install -U auditwheel', # Currently necessary on dockcross images to get auditwheel 2.1 supporting AUDITWHEEL_PLAT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import os
from utils import utils


PROJECT_DIR = os.path.dirname(__file__)


def test(utils):
# this test checks that SSL is working in the build environment using
# some checks in setup.py.

utils.cibuildwheel_run(PROJECT_DIR)
utils.cibuildwheel_run()
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import os, pytest
from utils import utils


PROJECT_DIR = os.path.dirname(__file__)


def test(utils):
Expand All @@ -12,7 +8,7 @@ def test(utils):
# build the wheels
# CFLAGS environment veriable is ecessary to fail on 'malloc_info' (on manylinux1) during compilation/linking,
# rather than when dynamically loading the Python
utils.cibuildwheel_run(PROJECT_DIR, add_env={
utils.cibuildwheel_run(add_env={
'CIBW_ENVIRONMENT': 'CFLAGS="$CFLAGS -Werror=implicit-function-declaration"',
})

Expand Down
2 changes: 2 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
This folder contains repos that are built by cibuildwheel to test cibuildwheel. Confusing, I know.

Basically, if cibuildwheel can build these projects, we're good.

All projects rely on the `utils` fixture defined in `conftest.py`
Empty file added test/__init__.py
Empty file.
9 changes: 9 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'''
pytest conftest.py.
'''


import test.shared.utils


utils = test.shared.utils.utils # export the utils fixture to be usable by any test
Empty file added test/shared/__init__.py
Empty file.
Loading

0 comments on commit 8df156e

Please sign in to comment.