Skip to content

Commit

Permalink
Fix error with pytest v7 (#49)
Browse files Browse the repository at this point in the history
* Bump pytest version

* Pin pytest version

* Fix tests

* Fix error

* Fix error in CI

* Drop 3.8 from matrix

* Unpin pytest in setup deps

* Remove logging

* Add section about compatibility between versions
  • Loading branch information
mondeja authored Mar 11, 2022
1 parent 7e3abea commit 064d5b4
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.2.1
current_version = 1.2.2

[bumpversion:file:pytest_blender/__init__.py]

Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ jobs:
platform:
- ubuntu-latest
- macos-latest
pytest-version:
- '7.0.1'
- '6.2.5'
blender-version:
- '2.93.5'
- '2.92.0'
- '2.91.2'
- '2.90.1'
- '2.93.5'
python-version:
- 3.6
- '3.9'
- '3.10'
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -54,12 +55,11 @@ jobs:
- name: Install dependencies
id: install-dependencies
run: |
python -m pip install .[test]
python -m pip install .[test] pytest==${{ matrix.pytest-version }}
blender_executable="$(< _blender-executable-path.txt tr -d '\n')"
python_blender_executable="$(pytest-blender --blender-executable $blender_executable)"
$python_blender_executable -m ensurepip
pytest_version="$(< setup.cfg grep pytest== | head -n 1 | cut -d'=' -f3)"
$python_blender_executable -m pip install pytest==$pytest_version
$python_blender_executable -m pip install pytest==${{ matrix.pytest-version }}
echo "::set-output name=blender-executable::$blender_executable"
- name: Test with Blender Python executable (no cache)
run: pytest -svv -p no:cacheprovider --blender-executable "${{ steps.install-dependencies.outputs.blender-executable }}" tests
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ You can use the `--blender-template` argument to pass a custom startup file:
pytest -svv --blender-template ~/.config/blender/2.93/config/startup.blend
```

#### Enable logging

Sometimes is useful to print debugging messages from `pytest_blender`.
You can enable logging in your `conftest.py` file by the next way:

```python
import logging

pytest_blender_logger = logging.getLogger("pytest_blender")
pytest_blender_logger.setLevel(logging.DEBUG)
pytest_blender_logger.addHandler(logging.StreamHandler())
```

### Reference

#### Fixtures
Expand Down Expand Up @@ -254,6 +267,10 @@ jobs:
run: pytest -svv --blender-executable "${{ steps.install-dependencies.outputs.blender-executable }}" tests
```
### Versions compatibility
- Latest version that officially supports Python3.6 is [v1.2.1]
[pypi-link]: https://pypi.org/project/pytest-blender
[pypi-version-badge-link]: https://img.shields.io/pypi/v/pytest-blender?logo=pypi&logoColor=white
Expand All @@ -265,3 +282,4 @@ jobs:
[pypi-downloads-image]: https://img.shields.io/pypi/dm/pytest-blender?logo=blender&logoColor=white
[pypi-downloads-link]: https://pypistats.org/packages/pytest-blender
[blender-downloader-link]: https://github.com/mondeja/blender-downloader
[v1.2.1]: https://github.com/mondeja/pytest-blender/releases/tag/v1.2.1
2 changes: 1 addition & 1 deletion pytest_blender/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.2.1"
__version__ = "1.2.2"
12 changes: 7 additions & 5 deletions pytest_blender/plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""pytest-blender plugin"""

import io
import logging
import os
import signal
import subprocess
Expand All @@ -11,6 +12,9 @@
from pytest_blender.utils import which_blender_by_os


logger = logging.getLogger("pytest_blender")


def pytest_addoption(parser):
parser.addoption(
"--blender-executable",
Expand Down Expand Up @@ -74,10 +78,7 @@ def pytest_configure(config):
pytest_opts, blender_opts, python_opts = args_groups

# run pytest using blender
args = [
blender_executable,
"-b",
]
args = [blender_executable, "-b"]

# template to open
_add_template_arg(config, args)
Expand All @@ -97,12 +98,13 @@ def pytest_configure(config):
*pytest_opts, # propagate Pytest command line arguments
]
)
logger.debug(f"Running blender from pytest-blender. CMD: {args}")
proc = subprocess.Popen(args, stdout=sys.stdout, stderr=sys.stderr)

def handled_exit():
# hide "Exit:" message shown by pytest on exit
sys.stderr = io.StringIO()
pytest.exit("", returncode=proc.returncode)
pytest.exit(" ", returncode=proc.returncode)

def on_sigint(signum, frame):
proc.send_signal(signum)
Expand Down
9 changes: 4 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = pytest_blender
version = 1.2.1
version = 1.2.2
description = Blender Pytest plugin.
long_description = file: README.md
long_description_content_type = text/markdown
Expand All @@ -15,7 +15,6 @@ classifiers =
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Expand All @@ -27,7 +26,7 @@ project_urls =

[options]
packages = pytest_blender
python_requires = >=3.6
python_requires = >=3.7

[options.entry_points]
console_scripts =
Expand All @@ -44,7 +43,7 @@ dev =
flake8-print==4.0.0
isort==5.9.1
pre-commit==2.13.0
pytest==6.2.5
pytest
yamllint==1.26.1
lint =
black==20.8b1
Expand All @@ -54,7 +53,7 @@ lint =
isort==5.9.1
yamllint==1.26.1
test =
pytest==6.2.5
pytest

[flake8]
max-line-length = 88
Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
"""pytest-blender tests configuration."""

import io
import logging
import os
import sys
from contextlib import redirect_stdout

import pytest


pytest_blender_logger = logging.getLogger("pytest_blender")
pytest_blender_logger.setLevel(logging.DEBUG)
pytest_blender_logger.addHandler(logging.StreamHandler())

try:
from pytest_blender.test import pytest_blender_active
except ImportError:
Expand Down
16 changes: 13 additions & 3 deletions tests/test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import re
import shutil
import subprocess

import pytest
Expand All @@ -18,16 +19,25 @@
reason="Requires testing loading the pytest-blender plugin.",
)
def test_blender_executable(blender_executable):
assert os.path.isfile(blender_executable)
assert "blender" in os.path.basename(blender_executable).lower()
assert blender_executable
blender_executable_path = shutil.which(blender_executable)
if not os.path.isfile(blender_executable_path):
assert os.path.islink(blender_executable_path)
else:
assert os.path.isfile(blender_executable_path)
assert "blender" in os.path.basename(blender_executable_path).lower()


@pytest.mark.skipif(
pytest_blender_unactive,
reason="Requires testing loading the pytest-blender plugin.",
)
def test_blender_python_executable(blender_python_executable):
assert os.path.isfile(blender_python_executable)
assert blender_python_executable
if not os.path.isfile(blender_python_executable):
assert os.path.islink(blender_python_executable)
else:
assert os.path.isfile(blender_python_executable)
assert "python" in os.path.basename(blender_python_executable)


Expand Down

0 comments on commit 064d5b4

Please sign in to comment.