Repository: NyanKiyoshi/pytest-django-queries (language: python)

Issue:
Plugin is broken with latest major pytest-xdist release
**Describe the bug**
In pytest-xdist 2.0 they dropped the `slave` terminology to `worker`: https://github.com/pytest-dev/pytest-xdist/commit/de3e54fd278d49b9b5d64e64f5942512519545e5#diff-ef40a8ca3f5a941cc38cb73ed8ae83ad

**To Reproduce**
Steps to reproduce the behavior:
1. Upgrade to latest pytest-xdist
2. Attempt to run tests using the plugins (xdist and django-queries)
3. See the crash

**Expected behavior**
Be compatible with latest major version of pytest-xdist: 2.0 and 2.1 but as well as the previous minor version.



Discussion / hints:

Fix patch:
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index dcf2296..28bf5e8 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,23 +1,27 @@
 repos:
 -   repo: https://github.com/ambv/black
-    rev: 18.9b0
+    rev: 20.8b1
     hooks:
     - id: black
       language_version: python3
 
 -   repo: https://github.com/pre-commit/pre-commit-hooks
-    rev: v2.1.0
+    rev: v3.2.0
     hooks:
     -   id: trailing-whitespace
     -   id: end-of-file-fixer
+
+- repo: https://gitlab.com/pycqa/flake8
+  rev: 3.8.3
+  hooks:
     -   id: flake8
 
 -   repo: https://github.com/asottile/seed-isort-config
-    rev: v1.9.0
+    rev: v2.2.0
     hooks:
     -   id: seed-isort-config
 
 -   repo: https://github.com/pre-commit/mirrors-isort
-    rev: v4.3.18
+    rev: v5.4.2
     hooks:
     -   id: isort
diff --git a/.travis.yml b/.travis.yml
index 139a403..21694e5 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,13 +1,14 @@
-sudo: false
+dist: xenial
+os: linux
 language: python
 
 git:
   depth: false
 
 python:
-  - "2.7"
-  - "3.4"
-  - "3.5"
+  - "3.6"
+  - "3.7"
+  - "3.8"
 
 cache:
   pip: true
@@ -18,75 +19,49 @@ cache:
 
 env:
   - DJANGO="==1.11.*"
+  - DJANGO="==2.0.*"
   - DJANGO="==2.1.*"
   - DJANGO="==2.2.*"
+  - DJANGO="==3.0.*"
+  - DJANGO="==3.1.*"
   - DJANGO="master"
   - TEST_PYPI="true"
 
-matrix:
+jobs:
   fast_finish: true
   include:
-    - dist: xenial
-      python: "3.5"
+    - python: "3.8"
       env:
-        - DJANGO="==2.2.*"
-
-    - dist: xenial
-      python: "3.6"
-      env:
-        - DJANGO="==2.2.*"
-
-    - dist: xenial
-      python: "3.6"
-      env:
-        - DJANGO="master"
+        - TEST_PRECOMMIT="true"
 
-    - dist: xenial
-      python: "3.7"
+    - python: "3.8"
       env:
-        - DJANGO="==2.2.*"
+        - DJANGO="==3.1.*"
+        - TEST_PYTEST_XDIST_134="==3.1.*"
 
-    - dist: xenial
-      python: "3.7"
-      env:
-        - DJANGO="master"
+  exclude:
+    - python: "3.8"
+      env: DJANGO="==1.11.*"
 
-    - dist: xenial
-      python: "3.6"
-      env:
-        - TEST_PRECOMMIT="true"
+    - python: "3.8"
+      env: DJANGO="==2.0.*"
 
-  exclude:
-    - python: "2.7"
-      env: DJANGO="==2.1.*"
-    - python: "2.7"
-      env: DJANGO="==2.2.*"
-    - python: "2.7"
-      env: DJANGO="master"
-    - python: "3.4"
+    - python: "3.8"
       env: DJANGO="==2.1.*"
-    - python: "3.4"
-      env: DJANGO="==2.2.*"
-    - python: "3.4"
-      env: DJANGO="master"
-    - python: "3.5"  # We need to use xenial here instead of trusty
-      env: DJANGO="==2.2.*"
-    - python: "3.5"
-      env: DJANGO="master"
 
 before_install:
   - sudo apt-get update
   - sudo apt-get install -y sqlite3
 
 install:
-  - >
+  - |
     if [ -n "$DJANGO" ]; then
       [ "$DJANGO" == master ] \
          && django=https://github.com/django/django/archive/master.tar.gz \
          || django="django${DJANGO}"
     fi
-  - pip install pytest-xdist tox-travis codecov coverage $django
-  - >
+  - pip install -r requirements_test.txt $django
+  - |
     if [ -n "$TEST_PYPI" ]; then
       if [ -n "$TRAVIS_TAG" ]; then
         pip install -r requirements_dev.txt
@@ -98,10 +73,12 @@ install:
       ./setup.py develop \
       && pip install -e .[dev]
     fi
+  - |
+    [ -z "$TEST_PYTEST_XDIST_134" ] || pip install pytest-xdist\<2.0
 
 
 script:
-  - >
+  - |
     if [ -n "$TEST_PYPI" ]; then
       if [ -n "$TRAVIS_TAG" ]; then
         pytest
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index e5ed8b5..b35f291 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,3 +1,11 @@
+v1.2rc0 - September 3rd 2020
+++++++++++++++++++++++++++++
+- Some tests were fixed as they were in a failing state from a old file reformatting.
+- pytest-xdist compatibility was fixed for latest major version: 2.0. The bad terminologies (slaves and masters) were removed.
+- Deprecated support of pytest-xdist <2.0, will be dropped on pytest-django-queries 2.0 release.
+- Official compatibility for Python 2.7, 3.4 and 3.5 was dropped as many dependencies are no longer supporting those versions. Use this plugin on those Python versions at your own risk.
+
+
 v1.1.0 - June 1st 2019
 ++++++++++++++++++++++
 
diff --git a/README.md b/README.md
index 55e5778..38e19da 100644
--- a/README.md
+++ b/README.md
@@ -15,8 +15,8 @@
     <a href='https://pypi.python.org/pypi/pytest-django-queries'>
       <img src='https://img.shields.io/pypi/v/pytest-django-queries.svg' alt='Version' />
     </a>
-    <a href="https://pypi.org/project/pytest-django-queries/1.1.0/">
-      <img src="https://img.shields.io/badge/pypi%20unstable-v1.1.0-FF0000.svg" alt="Latest Unstable on pypi">
+    <a href="https://pypi.org/project/pytest-django-queries/1.2rc0/">
+      <img src="https://img.shields.io/badge/pypi%20unstable-v1.2rc0-FF0000.svg" alt="Latest Unstable on pypi">
     </a>
   </p>
   <p>
@@ -161,9 +161,9 @@ First of all, clone the project locally. Then, install it using the below comman
 ./setup.py develop
 ```
 
-After that, you need to install the development requirements. For that,
+After that, you need to install the development and testing requirements. For that,
 run the below command.
 
 ```shell
-pip install -e .[dev]
+pip install -e .[test]
 ```
diff --git a/VERSION.txt b/VERSION.txt
index 9084fa2..d982e3e 100644
--- a/VERSION.txt
+++ b/VERSION.txt
@@ -1,1 +1,1 @@
-1.1.0
+1.2rc0
diff --git a/docs/conf.py b/docs/conf.py
index 7fbf360..469ad8c 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -26,12 +26,12 @@ def _read_root_file(filename):
 
 # -- Project information -----------------------------------------------------
 
-project = u"pytest-django-queries"
-copyright = u"2019, KOCAK Mikail (NyanKiyoshi)"
-author = u"KOCAK Mikail (NyanKiyoshi)"
+project = "pytest-django-queries"
+copyright = "2019, KOCAK Mikail (NyanKiyoshi)"
+author = "KOCAK Mikail (NyanKiyoshi)"
 
 # The short X.Y version
-version = u""
+version = ""
 # The full version, including alpha/beta/rc tags
 release = _read_root_file("VERSION.txt")
 
@@ -135,8 +135,8 @@ def _read_root_file(filename):
     (
         master_doc,
         "pytest-django-queries.tex",
-        u"pytest-django-queries Documentation",
-        u"KOCAK Mikail (NyanKiyoshi)",
+        "pytest-django-queries Documentation",
+        "KOCAK Mikail (NyanKiyoshi)",
         "manual",
     )
 ]
@@ -150,7 +150,7 @@ def _read_root_file(filename):
     (
         master_doc,
         "pytest-django-queries",
-        u"pytest-django-queries Documentation",
+        "pytest-django-queries Documentation",
         [author],
         1,
     )
@@ -166,7 +166,7 @@ def _read_root_file(filename):
     (
         master_doc,
         "pytest-django-queries",
-        u"pytest-django-queries Documentation",
+        "pytest-django-queries Documentation",
         author,
         "pytest-django-queries",
         "One line description of project.",
diff --git a/docs/index.rst b/docs/index.rst
index e7743cd..d48c072 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -7,7 +7,7 @@ This is used to detect and correct features that are missing optimizations or th
 
 This is also used to quickly see and compare differences of made changes through the included diff tool.
 
-This tool supports the Python versions: 2.7, 3.4, 3.5, 3.6, 3.7, and 3.8.
+This tool supports the Python versions: 3.6, 3.7, and 3.8.
 
 
 Quick Start
diff --git a/setup.py b/setup.py
index 92a7324..4701eb0 100755
--- a/setup.py
+++ b/setup.py
@@ -14,6 +14,7 @@ def _read_file(path):
 
 REQUIREMENTS = _read_file("requirements.txt").split("\n")
 DEV_REQUIREMENTS = _read_file("requirements_dev.txt").split("\n")
+TEST_REQUIREMENTS = _read_file("requirements_test.txt").split("\n")
 
 
 if isfile("README.md"):
@@ -43,9 +44,6 @@ def _read_file(path):
         "License :: OSI Approved :: BSD License",
         "Operating System :: OS Independent",
         "Programming Language :: Python",
-        "Programming Language :: Python :: 2.7",
-        "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",
@@ -55,6 +53,9 @@ def _read_file(path):
         "Topic :: Software Development :: Libraries :: Python Modules",
     ],
     install_requires=REQUIREMENTS,
-    extras_require={"dev": DEV_REQUIREMENTS},
+    extras_require={
+        "dev": DEV_REQUIREMENTS,
+        "test": TEST_REQUIREMENTS + DEV_REQUIREMENTS,
+    },
     zip_safe=False,
 )


Test patch:
diff --git a/pytest_django_queries/plugin.py b/pytest_django_queries/plugin.py
index a69abce..62231c3 100644
--- a/pytest_django_queries/plugin.py
+++ b/pytest_django_queries/plugin.py
@@ -2,6 +2,7 @@
 import os.path
 import shutil
 import tempfile
+import warnings
 from os import listdir
 from os.path import isfile
 
@@ -17,13 +18,27 @@
 DEFAULT_OLD_RESULT_FILENAME = ".pytest-queries.old"
 
 
-def is_slave(config):
-    return hasattr(config, "slaveinput")
+def get_worker_input(node):
+    workerinput = getattr(node, "workerinput", None)
+    if workerinput is None:
+        workerinput = node.slaveinput
+        warnings.warn(
+            "pytest-xdist<2.0 support will be dropped in pytest-django-queries 2.0",
+            category=DeprecationWarning,
+        )
+    return workerinput
+
+
+def is_worker(config):
+    return hasattr(config, "workerinput") or hasattr(config, "slaveinput")
 
 
-def get_slaveid(config):
-    if hasattr(config, "slaveinput"):
-        return config.workerinput["slaveid"]
+def get_workerid(config):
+    if hasattr(config, "workerinput"):
+        return config.workerinput["workerid"]
+    elif hasattr(config, "slaveinput"):
+        # Deprecated: will be removed in pytest-django-queries 2.0
+        return config.slaveinput["slaveid"]
     else:
         return "master"
 
@@ -49,7 +64,7 @@ def add_entry(request, queries, dirout):
         query_count,
         duplicate_count,
     )
-    save_path = os.path.join(dirout, get_slaveid(request.config))
+    save_path = os.path.join(dirout, get_workerid(request.config))
     if os.path.isfile(save_path):
         mode = "a"
     else:
@@ -166,7 +181,8 @@ def pytest_unconfigure(config):
 
 
 def pytest_configure_node(node):
-    node.slaveinput[
+    workerinput = get_worker_input(node)
+    workerinput[
         "_django_queries_shared_dir"
     ] = node.config.django_queries_shared_directory
 
@@ -178,10 +194,10 @@ def get_shared_directory(request):
     """Returns a unique and temporary directory which can be shared by
     master or worker nodes in xdist runs.
     """
-    if not is_slave(request.config):
+    if not is_worker(request.config):
         return request.config.django_queries_shared_directory
     else:
-        return request.config.slaveinput["_django_queries_shared_dir"]
+        return get_worker_input(request.config)["_django_queries_shared_dir"]
 
 
 @pytest.fixture
diff --git a/requirements_test.txt b/requirements_test.txt
new file mode 100644
index 0000000..97337c7
--- /dev/null
+++ b/requirements_test.txt
@@ -0,0 +1,4 @@
+pytest-xdist
+tox-travis
+codecov
+coverage
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 62f0710..5d1b85b 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -15,8 +15,9 @@ def test_load_invalid_json_file_triggers_error(testdir):
     result = runner.invoke(cli.main, ["show", "test_file.json"])
     assert result.exit_code == 2, result.stdout
     assert (
-        'Error: Invalid value for "[INPUT_FILE]": ' "The file is not valid json: "
-    ) in result.stdout
+        "Error: Invalid value for '[INPUT_FILE]': The file is not valid json"
+        in result.stdout
+    )
 
 
 def test_load_invalid_base_type_json_file_triggers_error(testdir):
@@ -219,7 +220,7 @@ def test_export_to_html_using_invalid_custom_template_should_fail(testdir):
     )
     assert result.exit_code == 2, result.stdout
     assert (
-        'Error: Invalid value for "--template": '
+        "Error: Invalid value for '--template': "
         "The file is not a valid jinja2 template: tag name expected" in result.stdout
     )
 
diff --git a/tests/test_cli_diff.py b/tests/test_cli_diff.py
index 379763c..716a90d 100644
--- a/tests/test_cli_diff.py
+++ b/tests/test_cli_diff.py
@@ -15,7 +15,7 @@ def test_show_diff(testdir, valid_comparison_entries):
     result = runner.invoke(cli.main, ["diff", "left.json", "right.json"])
     assert result.exit_code == 0, result.stdout
     assert repr(result.stdout) == repr(
-        u"""\
+        """\
 # another module
   test name          \tleft count \tright count\tduplicate count
   -------------------\t-----------\t-----------\t---------------