Skip to content

Commit b74229c

Browse files
committed
Make tests work when not using virtualenv
Currently, some of them explicitly reference black via its path inside the virtual environment. In an environment where the venv is not used, but rather the distribution’s packages are used for making the dependencies like black available, this does not work. This changes it to use the black binary from the PATH. Since the official development guidelines document activating the virtualenv before running pytest, which will make the black binary available, it will still work when using the virtual environment. The CI systems (Travis and Azure Pipelines) didn’t activate the virtualenv but rather called pytest directly from the venv. This also changes this so CI also works. Signed-off-by: Simon Bruder <simon@sbruder.de>
1 parent 6ad300e commit b74229c

4 files changed

Lines changed: 24 additions & 10 deletions

File tree

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ python:
1616
- "3.9"
1717

1818
# Scripts to run at install stage
19-
install: ./configure --dev
19+
install: |
20+
./configure --dev
21+
source venv/bin/activate
2022
2123
# Scripts to run at script stage
22-
script: venv/bin/pytest
24+
script: pytest

azure-pipelines.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,44 +13,56 @@ jobs:
1313
image_name: ubuntu-18.04
1414
python_versions: ['3.6', '3.7', '3.8', '3.9', '3.10']
1515
test_suites:
16-
all: venv/bin/pytest -n 2 -vvs
16+
all: |
17+
source venv/bin/activate
18+
pytest -n 2 -vvs
1719
1820
- template: etc/ci/azure-posix.yml
1921
parameters:
2022
job_name: ubuntu20_cpython
2123
image_name: ubuntu-20.04
2224
python_versions: ['3.6', '3.7', '3.8', '3.9', '3.10']
2325
test_suites:
24-
all: venv/bin/pytest -n 2 -vvs
26+
all: |
27+
source venv/bin/activate
28+
pytest -n 2 -vvs
2529
2630
- template: etc/ci/azure-posix.yml
2731
parameters:
2832
job_name: macos1015_cpython
2933
image_name: macos-10.15
3034
python_versions: ['3.6', '3.7', '3.8', '3.9', '3.10']
3135
test_suites:
32-
all: venv/bin/pytest -n 2 -vvs
36+
all: |
37+
source venv/bin/activate
38+
pytest -n 2 -vvs
3339
3440
- template: etc/ci/azure-posix.yml
3541
parameters:
3642
job_name: macos11_cpython
3743
image_name: macos-11
3844
python_versions: ['3.7', '3.8', '3.9', '3.10']
3945
test_suites:
40-
all: venv/bin/pytest -n 2 -vvs
46+
all: |
47+
source venv/bin/activate
48+
pytest -n 2 -vvs
4149
4250
- template: etc/ci/azure-win.yml
4351
parameters:
4452
job_name: win2019_cpython
4553
image_name: windows-2019
4654
python_versions: ['3.6', '3.7', '3.8', '3.9', '3.10']
4755
test_suites:
48-
all: venv\Scripts\pytest -n 2 -vvs
56+
all: |
57+
call venv\Scripts\activate.bat
58+
pytest -n 2 -vvs
4959
5060
- template: etc/ci/azure-win.yml
5161
parameters:
5262
job_name: win2022_cpython
5363
image_name: windows-2022
5464
python_versions: ['3.7', '3.8', '3.9', '3.10']
5565
test_suites:
56-
all: venv\Scripts\pytest -n 2 -vvs
66+
all: |
67+
call venv\Scripts\activate.bat
68+
pytest -n 2 -vvs

tests/test_codestyle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class BaseTests(unittest.TestCase):
1212
def test_codestyle(self):
13-
args = "venv/bin/black --check -l 100 setup.py src tests"
13+
args = "black --check -l 100 setup.py src tests"
1414
try:
1515
subprocess.check_output(args.split())
1616
except subprocess.CalledProcessError as e:

tests/test_skeleton_codestyle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_skeleton_codestyle(self):
2222
if setup_cfg["metadata"]["name"] != "skeleton":
2323
return
2424

25-
args = "venv/bin/black --check -l 100 setup.py etc tests"
25+
args = "black --check -l 100 setup.py etc tests"
2626
try:
2727
subprocess.check_output(args.split())
2828
except subprocess.CalledProcessError as e:

0 commit comments

Comments
 (0)