Skip to content

Commit

Permalink
Test: Changed collection of .yaml files to address pytest Deprecation…
Browse files Browse the repository at this point in the history
…Warning

Details:

* The collection of .yaml files in function tests that is implemented in
  tests/functiontest/conftest.py directly created the YamlItem and YamlFile
  objects using their constructors. Pytest 6.0.0 has deprecated that
  approach and has introduced class methods 'from_parent()' for this
  purpose, and they also do support additional kwargs like the ctors do.

  This change uses the from_parent() methods in both cases if the
  method exists on the object, and uses direct creation otherwise.
  The latter was necessary because we have to pin pytest to <5.0.0 on
  py27 and py34, and to <6.0.0 on py35.

Signed-off-by: Andreas Maier <andreas.r.maier@gmx.de>
  • Loading branch information
andy-maier committed Oct 2, 2020
1 parent 952754b commit 618e513
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Released: not yet

* Windows install: Upgraded WinOpenSSL to 1.1.1h.

* Test: Changed collection of .yaml files in function tests to address
DeprecationWarning issued by pytest (see issue #2430).

**Enhancements:**

* Removed dependency on package custom-inherit and removed package from
Expand Down
21 changes: 19 additions & 2 deletions tests/functiontest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,13 @@ def pytest_collect_file(parent, path):
https://docs.pytest.org/en/latest/example/nonpython.html
"""
if path.ext == ".yaml":
return YamlFile(path, parent)
if hasattr(YamlFile, 'from_parent'):
# pylint: disable=no-member
return YamlFile.from_parent(fspath=path, parent=parent)
# Direct creation has been deprecated in pytest, but
# from_parent() was introduced only in pytest 6.0.0 and we
# have to pin to lower pytest versions on py27/py34/py35.
return YamlFile(fspath=path, parent=parent)
return None # to avoid pylint inconsistent-return-statements


Expand Down Expand Up @@ -246,7 +252,18 @@ def collect(self):
except KeyError:
raise ClientTestError("Test case #%s does not have a "
"'name' attribute" % i + 1)
yield YamlItem(tc_name, self, testcase, filepath)
if hasattr(YamlItem, 'from_parent'):
# pylint: disable=no-member
yield YamlItem.from_parent(
name=tc_name, parent=self,
testcase=testcase, filepath=filepath)
else:
# Direct creation has been deprecated in pytest, but
# from_parent() was introduced only in pytest 6.0.0 and we
# have to pin to lower pytest versions on py27/py34/py35.
yield YamlItem(
name=tc_name, parent=self,
testcase=testcase, filepath=filepath)


class YamlItem(pytest.Item):
Expand Down

0 comments on commit 618e513

Please sign in to comment.