diff --git a/kolibri/core/deviceadmin/tests/test_dbrestore.py b/kolibri/core/deviceadmin/tests/test_dbrestore.py index 92eb712f30e..c0f583d0b50 100644 --- a/kolibri/core/deviceadmin/tests/test_dbrestore.py +++ b/kolibri/core/deviceadmin/tests/test_dbrestore.py @@ -109,6 +109,11 @@ def test_fail_on_unknown_file(): get_dtm_from_backup_name("this-file-has-no-time") +def _clear_backups(folder): + for f in os.listdir(folder): + os.remove(os.path.join(folder, f)) + + @pytest.mark.django_db @pytest.mark.filterwarnings("ignore:Overriding setting DATABASES") def test_restore_from_latest(): @@ -146,6 +151,7 @@ def test_restore_from_latest(): assert ( Facility.objects.filter(name="test latest", kind=FACILITY).count() == 1 ) + _clear_backups(default_backup_folder()) @pytest.mark.django_db @@ -176,6 +182,7 @@ def test_restore_from_file_to_memory(): call_command("dbrestore", backup) # Test that the user has been restored! assert Facility.objects.filter(name="test file", kind=FACILITY).count() == 1 + _clear_backups(dest_folder) @pytest.mark.django_db @@ -212,6 +219,7 @@ def test_restore_from_file_to_file(): call_command("dbrestore", backup) # Test that the user has been restored! assert Facility.objects.filter(name="test file", kind=FACILITY).count() == 1 + _clear_backups(dest_folder) def test_search_latest(): diff --git a/kolibri/core/discovery/test/test_network_broadcast.py b/kolibri/core/discovery/test/test_network_broadcast.py index 21ec1b6a19d..b2c20fc40ea 100644 --- a/kolibri/core/discovery/test/test_network_broadcast.py +++ b/kolibri/core/discovery/test/test_network_broadcast.py @@ -242,7 +242,7 @@ def test_is_broadcasting(self): self.broadcast.zeroconf = self.zeroconf self.assertTrue(self.broadcast.is_broadcasting) - @pytest.mark.skipIf(ZEROCONF_NEEDS_UPDATE, "Needs updated Zeroconf") + @pytest.mark.skipif(ZEROCONF_NEEDS_UPDATE, reason="Needs updated Zeroconf") def test_addresses(self): self.assertEqual(set(), self.broadcast.addresses) self.broadcast.zeroconf = self.zeroconf @@ -279,7 +279,7 @@ def test_update_broadcast__instance(self, mock_renew): self.assertEqual("abc-1", self.broadcast.instance.zeroconf_id) mock_renew.assert_called_once() - @pytest.mark.skipIf(ZEROCONF_NEEDS_UPDATE, "Needs updated Zeroconf") + @pytest.mark.skipif(ZEROCONF_NEEDS_UPDATE, reason="Needs updated Zeroconf") def test_update_broadcast__interfaces(self): new_interfaces = [MOCK_INTERFACE_IP] self.assertNotEqual(new_interfaces, self.broadcast.interfaces) diff --git a/pytest.ini b/pytest.ini index fb814f8f029..27a4c6aa780 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,4 +1,5 @@ [pytest] +addopts = --create-db testpaths = test/ kolibri/ norecursedirs = dist tmp* .svn .* # Settings for pytest-django diff --git a/requirements/test.txt b/requirements/test.txt index dbc324ab500..2f9cee0cdf5 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -1,14 +1,14 @@ # These are for testing beautifulsoup4==4.8.2 -factory-boy==2.7.0 # pyup: ignore - Needs an update, called 'faker' now -fake-factory==0.5.7 # pyup: ignore Needs an update -coverage==4.5.1 +factory-boy==2.7.0 +fake-factory==0.5.7 +coverage==6.2 mock==2.0.0 mixer==6.0.1 -pytest==3.7.1 # pyup: < 4.0.0 -pytest-cov==2.5.1 -pytest-django==3.3.3 +pytest-cov==3.0.0 +pytest==6.2.5 +pytest-django==4.5.2 pytest-env==0.6.2 pytest-pythonpath==0.7.2 -attrs==19.1.0 +attrs==19.2.0 parameterized==0.8.1 diff --git a/test/patch_pytest.py b/test/patch_pytest.py deleted file mode 100644 index f57e5226690..00000000000 --- a/test/patch_pytest.py +++ /dev/null @@ -1,58 +0,0 @@ -""" -This script backports this Python 3.10 compatibility fix https://github.com/pytest-dev/pytest/pull/8540 -in order to allow pytest to run in Python 3.10 without upgrading to version 6.2.5 which does not support 2.7 -""" -import logging -import os -import subprocess -import sys - -import pytest - -logger = logging.getLogger(__name__) - - -def patch(): - site_packages_dir = os.path.dirname(pytest.__file__) - - patch_file = os.path.join(os.path.dirname(__file__), "pytest_3.10.patch") - - logger.info("Applying patch: " + str(patch_file)) - - # -N: insist this is FORWARD patch, don't reverse apply - # -p1: strip first path component - # -t: batch mode, don't ask questions - patch_command = [ - "patch", - "-N", - "-p1", - "-d", - site_packages_dir, - "-t", - "-i", - patch_file, - ] - logger.info(" ".join(patch_command)) - try: - # Use a dry run to establish whether the patch is already applied. - # If we don't check this, the patch may be partially applied (which is bad!) - subprocess.check_output(patch_command + ["--dry-run"]) - except subprocess.CalledProcessError as e: - if e.returncode == 1: - # Return code 1 means not all hunks could be applied, this usually - # means the patch is already applied. - logger.warning( - "Failed to apply patch (exit code 1), " - "assuming it is already applied: ", - str(patch_file), - ) - else: - raise e - else: - # The dry run worked, so do the real thing - subprocess.check_output(patch_command) - - -if __name__ == "__main__": - if sys.version_info >= (3, 10): - patch() diff --git a/test/pytest_3.10.patch b/test/pytest_3.10.patch deleted file mode 100644 index 4c933e99e65..00000000000 --- a/test/pytest_3.10.patch +++ /dev/null @@ -1,38 +0,0 @@ -diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py -index 4f96b9e8c..1aa5b12de 100644 ---- a/_pytest/assertion/rewrite.py -+++ b/_pytest/assertion/rewrite.py -@@ -587,10 +587,6 @@ class AssertionRewriter(ast.NodeVisitor): - return - # Insert some special imports at the top of the module but after any - # docstrings and __future__ imports. -- aliases = [ -- ast.alias(py.builtin.builtins.__name__, "@py_builtins"), -- ast.alias("_pytest.assertion.rewrite", "@pytest_ar"), -- ] - doc = getattr(mod, "docstring", None) - expect_docstring = doc is None - if doc is not None and self.is_rewrite_disabled(doc): -@@ -617,6 +613,22 @@ class AssertionRewriter(ast.NodeVisitor): - pos += 1 - else: - lineno = item.lineno -+ # Now actually insert the special imports. -+ if sys.version_info >= (3, 10): -+ aliases = [ -+ ast.alias("builtins", "@py_builtins", lineno=lineno, col_offset=0), -+ ast.alias( -+ "_pytest.assertion.rewrite", -+ "@pytest_ar", -+ lineno=lineno, -+ col_offset=0, -+ ), -+ ] -+ else: -+ aliases = [ -+ ast.alias("builtins", "@py_builtins"), -+ ast.alias("_pytest.assertion.rewrite", "@pytest_ar"), -+ ] - imports = [ - ast.Import([alias], lineno=lineno, col_offset=0) for alias in aliases - ] diff --git a/tox.ini b/tox.ini index 011f418a103..cf1afa50e77 100644 --- a/tox.ini +++ b/tox.ini @@ -25,7 +25,6 @@ deps = -r{toxinidir}/requirements/cext.txt commands = sh -c 'kolibri manage makemigrations --check' - python test/patch_pytest.py # Run the actual tests python -O -m pytest {posargs:--cov=kolibri --cov-report= --cov-append --color=no} kolibri python -O -m pytest {posargs:--cov=kolibri --cov-report= --cov-append --color=no} -p no:django test