Skip to content

Commit 1912e67

Browse files
committed
MAINT: Updates for pytest 8.1 and python 3.12
1 parent 2c934ec commit 1912e67

File tree

13 files changed

+59
-93
lines changed

13 files changed

+59
-93
lines changed

.github/workflows/base.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ jobs:
1414
list_nox_test_sessions:
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v2
18-
- uses: actions/setup-python@v1
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-python@v4
1919
with:
20-
python-version: 3.7
20+
python-version: "3.7"
2121
architecture: x64
2222

2323
- name: Install noxfile requirements
@@ -43,14 +43,14 @@ jobs:
4343
name: ${{ matrix.os }} ${{ matrix.nox_session }} # ${{ matrix.name_suffix }}
4444
runs-on: ${{ matrix.os }}
4545
steps:
46-
- uses: actions/checkout@v2
46+
- uses: actions/checkout@v4
4747

4848
# Conda install
49-
- name: Install conda v3.7
49+
- name: Install conda v3.12
5050
uses: conda-incubator/setup-miniconda@v2
5151
with:
5252
# auto-update-conda: true
53-
python-version: 3.7
53+
python-version: "3.12"
5454
activate-environment: noxenv
5555
- run: conda info
5656
shell: bash -l {0} # so that conda works
@@ -84,7 +84,7 @@ jobs:
8484
GITHUB_CONTEXT: ${{ toJSON(github) }}
8585
run: echo "$GITHUB_CONTEXT"
8686

87-
- uses: actions/checkout@v2
87+
- uses: actions/checkout@v4
8888
with:
8989
fetch-depth: 0 # so that gh-deploy works
9090

@@ -100,7 +100,7 @@ jobs:
100100
uses: conda-incubator/setup-miniconda@v2
101101
with:
102102
# auto-update-conda: true
103-
python-version: 3.7
103+
python-version: "3.12"
104104
activate-environment: noxenv
105105
- run: conda info
106106
shell: bash -l {0} # so that conda works

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,8 @@ You should then be able to list all available tasks using:
3131
>>> nox --list
3232
Sessions defined in <path>\noxfile.py:
3333
34-
* tests-2.7 -> Run the test suite, including test reports generation and coverage reports.
35-
* tests-3.5 -> Run the test suite, including test reports generation and coverage reports.
36-
* tests-3.6 -> Run the test suite, including test reports generation and coverage reports.
34+
* tests-3.12 -> Run the test suite, including test reports generation and coverage reports.
3735
* tests-3.8 -> Run the test suite, including test reports generation and coverage reports.
38-
* tests-3.7 -> Run the test suite, including test reports generation and coverage reports.
3936
- docs-3.7 -> Generates the doc and serves it on a local http server. Pass '-- build' to build statically instead.
4037
- publish-3.7 -> Deploy the docs+reports on github pages. Note: this rebuilds the docs
4138
- release-3.7 -> Create a release on github corresponding to the latest tag
@@ -49,7 +46,7 @@ This project uses `pytest` so running `pytest` at the root folder will execute a
4946
nox
5047
```
5148

52-
Tests and coverage reports are automatically generated under `./docs/reports` for one of the sessions (`tests-3.7`).
49+
Tests and coverage reports are automatically generated under `./docs/reports` for one of the sessions (`tests-3.7`).
5350

5451
If you wish to execute tests on a specific environment, use explicit session names, e.g. `nox -s tests-3.6`.
5552

ci_tools/nox_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
nox_logger = logging.getLogger("nox")
2222

2323

24-
PY27, PY35, PY36, PY37, PY38 = "2.7", "3.5", "3.6", "3.7", "3.8"
24+
PY38, PY312 = "3.8", "3.12"
2525
DONT_INSTALL = "dont_install"
2626

2727

docs/changelog.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
### 2.0.0 - updates for Python 3.8+
4+
5+
- Modernized for Python 3.8+ support only.
6+
37
### 1.10.4 - python 3.5 xdist bugfix
48

59
- Fixed issue with `pytest-xdist` and python 3.5: `pathlib` objects were not properly handled by other stdlib modules in this python version. Fixed [#59](https://github.com/smarie/python-pytest-harvest/issues/59)
@@ -144,31 +148,31 @@ Fixed pytest ordering issue, by relying on [place_as](https://github.com/pytest-
144148

145149
### 1.0.0 - new methods for pytest session analysis
146150

147-
New methods are provided to analyse pytest session results:
151+
New methods are provided to analyse pytest session results:
148152
- `filter_session_items(session, filter=None)` is the filtering method used behind several functions in this package - it can be used independently. `pytest_item_matches_filter` is the inner method used to test if a single item matches the filter.
149153
- `get_all_pytest_param_names(session, filter=None, filter_incomplete=False)` lists all unique parameter names used in pytest session items, with optional filtering capabilities. Fixes [#12](https://github.com/smarie/python-pytest-harvest/issues/12)
150-
- `is_pytest_incomplete(item)`, `get_pytest_status(item)`, `get_pytest_param_names(item)` and `get_pytest_params(item)` allow users to analyse a specific item.
154+
- `is_pytest_incomplete(item)`, `get_pytest_status(item)`, `get_pytest_param_names(item)` and `get_pytest_params(item)` allow users to analyse a specific item.
151155

152156

153157
### 0.9.0 - `get_session_synthesis_dct`: filter bugfix + test id formatter
154158

155159
* `get_session_synthesis_dct`:
156-
160+
157161
- `filter` now correctly handles class methods. Fixed [#11](https://github.com/smarie/python-pytest-harvest/issues/11)
158162
- new `test_id_format` option to process test ids. Fixed [#9](https://github.com/smarie/python-pytest-harvest/issues/9)
159163

160164
### 0.8.0 - Documentation + better filters in `get_session_synthesis_dct`
161165

162166
* Documentation: added a section about creating the synthesis table from *inside* a test function (fixes [#4](https://github.com/smarie/python-pytest-harvest/issues/4)). Also, added a link to a complete example file.
163-
167+
164168
* `get_session_synthesis_dct`: `filter` argument can now contain module names (fixed [#7](https://github.com/smarie/python-pytest-harvest/issues/7)). Also now the function filters out incomplete tests by default. A new `filter_incomplete` argument can be used to display them again (fixed [#8](https://github.com/smarie/python-pytest-harvest/issues/8)).
165169

166170
### 0.7.0 - Documentation + `get_session_synthesis_dct` improvements 2
167171

168172
* Results bags do not measure execution time anymore since this is much less accurate than pytest duration. Fixes [#6](https://github.com/smarie/python-pytest-harvest/issues/6)
169-
173+
170174
* `get_session_synthesis_dct` does not output the stage by stage details (setup/call/teardown) anymore by default, but a new option `status_details` allows users to enable them. Fixes [#5](https://github.com/smarie/python-pytest-harvest/issues/5)
171-
175+
172176
* `get_session_synthesis_dct` has also 2 new options `durations_in_ms` and `pytest_prefix` to better control the output.
173177

174178
* Improved documentation.

noxfile.py

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# add parent folder to python path so that we can import noxfile_utils.py
1010
# note that you need to "pip install -r noxfile-requiterements.txt" for this file to work.
1111
sys.path.append(str(Path(__file__).parent / "ci_tools"))
12-
from nox_utils import PY27, PY37, PY36, PY35, PY38, power_session, rm_folder, rm_file, PowerSession, DONT_INSTALL # noqa
12+
from nox_utils import PY38, PY312, power_session, rm_folder, rm_file, PowerSession, DONT_INSTALL # noqa
1313

1414

1515
pkg_name = "pytest_harvest"
@@ -18,35 +18,16 @@
1818

1919

2020
ENVS = {
21-
# python 3.8 - put first to detect easy issues faster.
21+
# python 3.12
22+
(PY312, "pytest7.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<8"}},
23+
(PY312, "pytest-latest"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": ""}},
24+
# python 3.8
2225
(PY38, "pytest2.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<3", "pytest-asyncio": DONT_INSTALL}}, # "pytest-html": "1.9.0",
2326
(PY38, "pytest3.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<4"}},
2427
(PY38, "pytest4.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<5"}},
2528
(PY38, "pytest5.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<6"}},
26-
(PY38, "pytest-latest"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": ""}},
27-
# python 2.7
28-
(PY27, "pytest2.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<3", "pytest-asyncio": DONT_INSTALL}}, # "pytest-html": "1.9.0",
29-
(PY27, "pytest3.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<4"}},
30-
(PY27, "pytest4.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<5"}},
31-
# python 3.5
32-
(PY35, "pytest2.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<3", "pytest-asyncio": DONT_INSTALL}}, # "pytest-html": "1.9.0",
33-
(PY35, "pytest3.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<4"}},
34-
(PY35, "pytest4.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<5"}},
35-
(PY35, "pytest5.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<6"}},
36-
(PY35, "pytest-latest"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": ""}},
37-
# python 3.6
38-
(PY36, "pytest2.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<3", "pytest-asyncio": DONT_INSTALL}}, # "pytest-html": "1.9.0",
39-
(PY36, "pytest3.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<4"}},
40-
(PY36, "pytest4.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<5"}},
41-
(PY36, "pytest5.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<6"}},
42-
(PY36, "pytest-latest"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": ""}},
43-
# python 3.7
44-
(PY37, "pytest2.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<3", "pytest-asyncio": DONT_INSTALL}}, # "pytest-html": "1.9.0",
45-
(PY37, "pytest3.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<4"}},
46-
(PY37, "pytest4.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<5"}},
47-
(PY37, "pytest5.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<6"}},
4829
# IMPORTANT: this should be last so that the folder docs/reports is not deleted afterwards
49-
(PY37, "pytest-latest"): {"coverage": True, "pkg_specs": {"pip": ">19", "pytest": ""}}
30+
(PY38, "pytest-latest"): {"coverage": True, "pkg_specs": {"pip": ">19", "pytest": ""}}
5031
}
5132

5233

@@ -156,7 +137,7 @@ def tests(session: PowerSession, coverage, pkg_specs):
156137
session.run2("python ci_tools/generate-junit-badge.py 100 %s" % Folders.test_reports)
157138

158139

159-
@power_session(python=[PY37])
140+
@power_session(python=[PY38])
160141
def docs(session: PowerSession):
161142
"""Generates the doc and serves it on a local http server. Pass '-- build' to build statically instead."""
162143

@@ -169,7 +150,7 @@ def docs(session: PowerSession):
169150
session.run2("mkdocs serve -f ./docs/mkdocs.yml")
170151

171152

172-
@power_session(python=[PY37])
153+
@power_session(python=[PY38])
173154
def publish(session: PowerSession):
174155
"""Deploy the docs+reports on github pages. Note: this rebuilds the docs"""
175156

@@ -194,7 +175,7 @@ def publish(session: PowerSession):
194175
# session.run2('codecov -t %s -f %s' % (codecov_token, Folders.coverage_xml))
195176

196177

197-
@power_session(python=[PY37])
178+
@power_session(python=[PY38])
198179
def release(session: PowerSession):
199180
"""Create a release on github corresponding to the latest tag"""
200181

pytest_harvest/fixture_cache.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from decopatch import DECORATED, function_decorator
55
from makefun import wraps, add_signature_parameters
6-
from six import string_types
76

87
from pytest_harvest.common import get_scope
98

@@ -81,7 +80,7 @@ def test_synthesis(fixture_store):
8180
key = key or fixture_name
8281

8382
# is the store a fixture or an object ?
84-
store_is_a_fixture = isinstance(store, string_types)
83+
store_is_a_fixture = isinstance(store, str)
8584

8685
# if the store object is already available, we can ensure that it is initialized. Otherwise trust pytest for that
8786
if not store_is_a_fixture:

pytest_harvest/plugin.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from logging import warning
44
from shutil import rmtree
55
import pytest
6-
import six
76

87
try:
98
from pathlib import Path
@@ -238,9 +237,9 @@ def get_session_results_df(session_or_request,
238237
"""
239238
try:
240239
import pandas as pd # pylint: disable=import-outside-toplevel
241-
except ImportError as e:
242-
six.raise_from(Exception("There was an error importing `pandas` module. Fixture `session_results_df` and method"
243-
"`get_session_results_df` can not be used in this session."), e)
240+
except ImportError:
241+
raise Exception("There was an error importing `pandas` module. Fixture `session_results_df` and method"
242+
"`get_session_results_df` can not be used in this session.")
244243

245244
# in case of xdist, make sure persisted workers results have been reloaded
246245
possibly_restore_xdist_workers_structs(session_or_request)
@@ -308,10 +307,10 @@ def get_filtered_results_df(session,
308307
"""
309308
try:
310309
import pandas as pd # pylint: disable=import-outside-toplevel
311-
except ImportError as e:
312-
six.raise_from(Exception("There was an error importing `pandas` module. Fixture `session_results_df` and "
313-
"methods `get_filtered_results_df` and `get_module_results_df` can not be used in this"
314-
" session. "), e)
310+
except ImportError:
311+
raise Exception("There was an error importing `pandas` module. Fixture `session_results_df` and "
312+
"methods `get_filtered_results_df` and `get_module_results_df` can not be used in this"
313+
" session. ")
315314

316315
# in case of xdist, make sure persisted workers results have been reloaded
317316
possibly_restore_xdist_workers_structs(session)

pytest_harvest/results_bags.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from datetime import datetime
22

33
import pytest
4-
from six import raise_from
54

65
try: # python 3+
76
from typing import Type, Set, Union, Any, Dict
@@ -25,19 +24,19 @@ def __setattr__(self, key, value):
2524
# try: No exception can happen: key is always a string, and new entries are allowed in a dict
2625
self[key] = value
2726
# except KeyError as e:
28-
# raise_from(AttributeError(key), e)
27+
# raise (AttributeError(key)
2928

3029
def __getattr__(self, key):
3130
try:
3231
return self[key]
3332
except KeyError as e:
34-
raise_from(AttributeError(key), e)
33+
raise AttributeError(key)
3534

3635
def __delattr__(self, key):
3736
try:
3837
del self[key]
3938
except KeyError as e:
40-
raise_from(AttributeError(key), e)
39+
raise AttributeError(key)
4140

4241
# object base
4342
def __str__(self):

pytest_harvest/results_session.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from distutils.version import LooseVersion
1+
from typing import Union, Iterable, Mapping, Any
2+
from packaging.version import parse
23

34
import pytest
45
import sys
56
from collections import OrderedDict, namedtuple
67
from itertools import chain
7-
from six import string_types
88

99

10-
pytest53 = LooseVersion(pytest.__version__) >= LooseVersion("5.3.0")
10+
pytest53 = parse(pytest.__version__) >= parse("5.3.0")
1111
if pytest53:
1212
def is_lazy_value_or_tupleitem_with_int_base(o):
1313
return False
@@ -24,15 +24,10 @@ def is_lazy_value_or_tupleitem_with_int_base(o):
2424
def is_lazy_value_or_tupleitem_with_int_base(o):
2525
return False
2626

27-
try: # python 3.5+
28-
from typing import Union, Iterable, Mapping, Any
29-
except ImportError:
30-
pass
31-
3227
from pytest_harvest.common import HARVEST_PREFIX
3328
from _pytest.doctest import DoctestItem
3429

35-
30+
pytest81 = parse(pytest.__version__) >= parse("8.1")
3631
PYTEST_OBJ_NAME = 'pytest_obj'
3732

3833

@@ -189,7 +184,7 @@ def test_id_format(test_id):
189184
if flatten_more is not None:
190185
if isinstance(flatten_more, dict):
191186
flatten_more_prefixes_dct = flatten_more.items()
192-
elif isinstance(flatten_more, string_types):
187+
elif isinstance(flatten_more, str):
193188
# single name ?
194189
flatten_more_prefixes_dct = {flatten_more: ''}
195190
else:
@@ -504,7 +499,9 @@ def get_pytest_params(item):
504499
if is_lazy_value_or_tupleitem_with_int_base(param_value):
505500
# remove the int base so that pandas does not interprete it as an int.
506501
param_value = param_value.clone(remove_int_base=True)
507-
if item.session._fixturemanager.getfixturedefs(param_name, item.nodeid) is not None:
502+
503+
arg = item if pytest81 else item.nodeid
504+
if item.session._fixturemanager.getfixturedefs(param_name, arg) is not None:
508505
# Fixture parameters have the same name than the fixtures themselves! change it
509506
param_dct[param_name + '_param'] = param_value
510507
else:
@@ -543,7 +540,7 @@ def _get_filterset(filter):
543540
:param filter:
544541
:return:
545542
"""
546-
if isinstance(filter, string_types):
543+
if isinstance(filter, str):
547544
filter = {filter}
548545
else:
549546
try:

pytest_harvest/tests/test_all_raw_with_meta_check.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from os.path import join, dirname, pardir
55

66
import pytest
7-
import six
87

98
# Make the list of all tests that we will have to execute (each in an independent pytest runner)
109
THIS_DIR = dirname(__file__)
@@ -60,6 +59,6 @@ def test_run_all_tests(test_to_run, testdir):
6059
# Here we check that everything is ok
6160
try:
6261
result.assert_outcomes(**asserts_dct)
63-
except Exception as e:
62+
except Exception:
6463
print("Error while asserting that %s results in %s" % (test_to_run, str(asserts_dct)))
65-
six.raise_from(e, e)
64+
raise

pytest_harvest/tests/test_lazy_and_harvest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import pytest
2-
from distutils.version import LooseVersion
2+
from packaging.version import parse
33

44
from pytest_cases import lazy_value, fixture_ref, parametrize, fixture
55

66
from pytest_harvest import get_session_synthesis_dct
77

88

9-
pytest2 = LooseVersion(pytest.__version__) < LooseVersion("3.0.0")
9+
pytest2 = parse(pytest.__version__) < parse("3.0.0")
1010

1111

1212
@fixture

0 commit comments

Comments
 (0)