Repository: wanderu/pytest-bandit (language: python)

Issue:
pytest 6 support
When using this plugin against pytest 6.1.0, I get the following error:

```bash
INTERNALERROR> Failed: Direct construction of BanditItem has been deprecated, please use BanditItem.from_parent.
INTERNALERROR> See https://docs.pytest.org/en/stable/deprecations.html#node-construction-changed-to-node-from-parent for more details.
```

Is this plugin compatible with the 6.x versions of pytest?


Discussion / hints:

Fix patch:
diff --git a/.travis.yml b/.travis.yml
index 6a36fee..1f44379 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,16 +6,22 @@ language: python
 
 matrix:
     include:
-      - python: 3.5
-        env: TOX_ENV=py35
       - python: 3.6
-        env: TOX_ENV=py36
+        env: TOX_ENV=py36-pytest5
+      - python: 3.6
+        env: TOX_ENV=py36-pytest6
+      - python: 3.7
+        env: TOX_ENV=py37-pytest5
       - python: 3.7
-        env: TOX_ENV=py37
+        env: TOX_ENV=py37-pytest6
       - python: 3.8
-        env: TOX_ENV=py38
+        env: TOX_ENV=py38-pytest5
+      - python: 3.8
+        env: TOX_ENV=py38-pytest6
+      - python: 3.9
+        env: TOX_ENV=py39-pytest5
       - python: 3.9
-        env: TOX_ENV=py39
+        env: TOX_ENV=py39-pytest6
       - python: 3.9
         env: TOX_ENV=flake8
 
@@ -23,7 +29,7 @@ install:
   - pip install tox
 
 script:
-  - tox -e $TOX_ENV
+  - tox -r -e $TOX_ENV
 
 before_cache:
   - rm -rf $HOME/.cache/pip/log
diff --git a/appveyor.yml b/appveyor.yml
index bc9f27d..dc4d8d3 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -9,9 +9,6 @@ environment:
     - PYTHON: "C:\\Python34"
       TOX_ENV: "py34"
 
-    - PYTHON: "C:\\Python35"
-      TOX_ENV: "py35"
-
     - PYTHON: "C:\\Python36"
       TOX_ENV: "py36"
 
diff --git a/setup.py b/setup.py
index dcaba01..03809fa 100644
--- a/setup.py
+++ b/setup.py
@@ -36,10 +36,10 @@ def read(fname):
         'Topic :: Software Development :: Testing',
         'Programming Language :: Python',
         'Programming Language :: Python :: 3',
-        'Programming Language :: Python :: 3.4',
-        'Programming Language :: Python :: 3.5',
         'Programming Language :: Python :: 3.6',
         'Programming Language :: Python :: 3.7',
+        'Programming Language :: Python :: 3.8',
+        'Programming Language :: Python :: 3.9',
         'Programming Language :: Python :: Implementation :: CPython',
         'Operating System :: OS Independent',
         'License :: OSI Approved :: MIT License',
diff --git a/tox.ini b/tox.ini
index c2af107..0eba4e0 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,10 +1,11 @@
 # For more information about tox, see https://tox.readthedocs.io/en/latest/
 [tox]
-envlist = py35,py36,py37,py38,py39,flake8
+envlist = py{36,37,38,39}-pytest{5,6},flake8
 
 [testenv]
 deps = 
-    pytest>=3.0,<6.0
+    pytest5: pytest>=5.0,<6.0
+    pytest6: pytest>=6.0,<7.0
     pytest-pycodestyle>=2.0.0
     pytest-cov>=2.5.1
 commands = pytest {posargs:tests}


Test patch:
diff --git a/pytest_bandit/controller.py b/pytest_bandit/controller.py
index 97351d8..469f004 100644
--- a/pytest_bandit/controller.py
+++ b/pytest_bandit/controller.py
@@ -17,10 +17,15 @@ class BanditItem(pytest.Item):
     CACHE_KEY = 'bandit/mtimes'
     MARKER = 'bandit'
 
-    def __init__(self, session):
-        super().__init__('bandit', session)
-        self.add_marker(self.MARKER)
-        self.config = session.config
+    @classmethod
+    def from_parent(cls, parent, name, **kwargs):
+        super_ = super()
+        if hasattr(super_, "from_parent"):
+            new = super_.from_parent(parent=parent, name=name)
+        else:
+            new = super_(name, parent)
+            new.config = parent.config
+        return new
 
     def setup(self):
         old_mtime = self.config.cache.get(
diff --git a/pytest_bandit/plugin.py b/pytest_bandit/plugin.py
index 53828c5..66e828c 100644
--- a/pytest_bandit/plugin.py
+++ b/pytest_bandit/plugin.py
@@ -188,7 +188,9 @@ def shouldfail(self, value):
 def pytest_runtestloop(session):
     yield
     compat_session = SessionWrapper(session)
-    bandit_failures = BanditItem(compat_session).runtest()
+    bandit_failures = BanditItem.from_parent(
+        parent=session, name='bandit'
+    ).runtest()
     LOG.debug(compat_session.shouldfail)
     compat_session.testsfailed += bandit_failures
     compat_session.shouldfail = bool(bandit_failures)