jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1041541?usp=email )

Change subject: [tests] discard PYWIKIBOT_TEST_WRITE_FAIL and use  
PYWIKIBOT_TEST_WRITE instead
......................................................................

[tests] discard PYWIKIBOT_TEST_WRITE_FAIL and use  PYWIKIBOT_TEST_WRITE instead

no reason found for this additional environemt variable except that
such tests  "are much safer than the other 'write' tests."

- remove environment variable from github write_tests action
- update SiteWriteMixin.setUpClass
- update documentation
- update tests, 'login' test attribute is implicit with 'write'

Change-Id: I31dd1a14df43d6ccc84371fe73908530b3d00aaa
---
M .github/workflows/write_tests-ci.yml
M tests/README.rst
M tests/aspects.py
M tests/edit_failure_tests.py
M tests/flow_edit_tests.py
M tests/thanks_tests.py
6 files changed, 43 insertions(+), 68 deletions(-)

Approvals:
  Xqt: Looks good to me, approved
  jenkins-bot: Verified




diff --git a/.github/workflows/write_tests-ci.yml 
b/.github/workflows/write_tests-ci.yml
index 7a923ed..6e6a661 100644
--- a/.github/workflows/write_tests-ci.yml
+++ b/.github/workflows/write_tests-ci.yml
@@ -63,7 +63,6 @@
       timeout-minutes: 90
       env:
         PYWIKIBOT_TEST_WRITE: ${{ matrix.site == 'wikipedia:test' && 1 || 0}}
-        PYWIKIBOT_TEST_WRITE_FAIL: ${{ matrix.site == 'wikipedia:test' && 1 || 
0}}
       run: |
         python pwb.py version
         pytest -s -r A -a "rights or write" --cov=.;
diff --git a/tests/README.rst b/tests/README.rst
index 11d526b..626875b 100644
--- a/tests/README.rst
+++ b/tests/README.rst
@@ -158,8 +158,12 @@
 **PYWIKIBOT_TEST_WRITE**
   There are also several other 'write' tests which also attempt to perform
   write operations successfully.  These **will** write to the wikis, and they
-  should always only write to 'test' wikis. Enabling them won't enable 'edit
-  failure' tests.
+  should always only write to 'test' wikis.
+
+  .. versionchanged:: 9.2
+     Enabling them will also enable 'edit failure' tests which attempt to write
+     to the wikis and **should** fail. If there is a bug in pywikibot or
+     MediaWiki, these tests **may** actually perform a write operation.

   To enable 'write' tests, set::

@@ -174,8 +178,9 @@

     PYWIKIBOT_TEST_WRITE_FAIL=1

-.. note:: Enabling only 'edit failure' tests or 'write' tests won't enable the
-   other tests automatically.
+  .. deprecated:: 9.2
+     this environment variable no longer has any effect; use
+     :envvar:`PYWIKIBOT_TEST_WRITE` instead.

 Instead of setting the environment by the os (or `os.environ` as well) you can 
use the :mod:`pwb`
 wrapper script to set it::
diff --git a/tests/aspects.py b/tests/aspects.py
index 039542a..18da72f 100644
--- a/tests/aspects.py
+++ b/tests/aspects.py
@@ -507,55 +507,48 @@

 class SiteWriteMixin(TestCaseBase):

-    """
-    Test cases involving writing to the server.
+    """Test cases involving writing to the server.
 
-    When editing, the API should not be patched to use
-    CachedRequest. This class prevents that.
+    When editing, the API should not be patched to use CachedRequest.
+    This class prevents that.
     """

     @classmethod
-    def setUpClass(cls):
-        """
-        Set up the test class.
+    def setUpClass(cls) -> None:
+        """Set up the test class.

-        Reject write test classes configured with non-test wikis, or caching.
+        Reject write test classes configured with non-test wikis, or
+        caching. Prevent test classes from writing to the site by
+        default.

-        Prevent test classes from writing to the site by default.
+        The test class is skipped unless environment variable
+        :envvar:`PYWIKIBOT_TEST_WRITE` is set to 1.

-        If class attribute 'write' is -1, the test class is skipped unless
-        environment variable PYWIKIBOT_TEST_WRITE_FAIL is set to 1.
+        .. versionchanged:: 9.2
+           :envvar:`PYWIKIBOT_TEST_WRITE_FAIL` environment variable was
+           discarded, see :ref:`Environment variables`.

-        Otherwise the test class is skipped unless environment variable
-        PYWIKIBOT_TEST_WRITE is set to 1.
+        :raises Exception: test class cannot use *write* attribute
+            together with *cached* and must be run on test sites only.
         """
         if issubclass(cls, ForceCacheMixin):
-            raise Exception(
-                '{} cannot be a subclass of both '
-                'SiteWriteMixin and ForceCacheMixin'
-                .format(cls.__name__))
+            raise Exception(f'{cls.__name__} cannot be a subclass of both'
+                            ' SiteWriteMixin and ForceCacheMixin')

         super().setUpClass()
-
         site = cls.get_site()

-        if cls.write == -1:
-            env_var = 'PYWIKIBOT_TEST_WRITE_FAIL'
-        else:
-            env_var = 'PYWIKIBOT_TEST_WRITE'
-
-        if os.environ.get(env_var, '0') != '1':
-            raise unittest.SkipTest(
-                f'{cls.__name__!r} write tests disabled. '
-                f'Set {env_var}=1 to enable.')
+        if os.environ.get('PYWIKIBOT_TEST_WRITE', '0') != '1':
+            raise unittest.SkipTest(f'{cls.__name__!r} write tests disabled.'
+                                    ' Set PYWIKIBOT_TEST_WRITE=1 to enable.')

         if (not hasattr(site.family, 'test_codes')
                 or site.code not in site.family.test_codes):
             raise Exception(
-                '{} should only be run on test sites. '
-                "To run this test, add '{}' to the {} family "
-                "attribute 'test_codes'."
-                .format(cls.__name__, site.code, site.family.name))
+                f'{cls.__name__} should only be run on test sites. To run '
+                f'this test, add {site.code!r} to the {site.family.name}'
+                " family attribute 'test_codes'."
+            )


 class RequireLoginMixin(TestCaseBase):
diff --git a/tests/edit_failure_tests.py b/tests/edit_failure_tests.py
index 960e4c8..ce984cb 100755
--- a/tests/edit_failure_tests.py
+++ b/tests/edit_failure_tests.py
@@ -1,14 +1,11 @@
 #!/usr/bin/env python3
-"""
-Tests for edit failures.
+"""Tests for edit failures.

-These tests should never write to the wiki,
-unless something has broken badly.
-
-These tests use special code 'write = -1' for edit failures.
+These tests should never write to the wiki, unless something has broken
+badly.
 """
 #
-# (C) Pywikibot team, 2014-2023
+# (C) Pywikibot team, 2014-2024
 #
 # Distributed under the terms of the MIT license.
 #
@@ -39,9 +36,7 @@

     """Test cases for edits which should fail to save."""

-    login = True
-    write = -1
-
+    write = True
     family = 'wikipedia'
     code = 'test'

@@ -109,9 +104,7 @@

     """Test cases for actions which should fail to save."""

-    login = True
-    write = -1
-
+    write = True
     family = 'wikipedia'
     code = 'test'

@@ -139,9 +132,7 @@

     family = 'wikidata'
     code = 'test'
-
-    login = True
-    write = -1
+    write = True

     def test_itempage_save(self):
         """Test ItemPage save method inherited from superclass Page."""
diff --git a/tests/flow_edit_tests.py b/tests/flow_edit_tests.py
index a080b4d..0fce47a 100755
--- a/tests/flow_edit_tests.py
+++ b/tests/flow_edit_tests.py
@@ -1,7 +1,7 @@
 #!/usr/bin/env python3
 """Edit tests for the flow module."""
 #
-# (C) Pywikibot team, 2015-2022
+# (C) Pywikibot team, 2015-2024
 #
 # Distributed under the terms of the MIT license.
 #
@@ -25,8 +25,6 @@

     family = 'wikipedia'
     code = 'test'
-
-    login = True
     write = True

     def test_create_topic(self):
@@ -64,8 +62,6 @@

     family = 'wikipedia'
     code = 'test'
-
-    login = True
     write = True

     @classmethod
@@ -185,8 +181,6 @@

     family = 'wikipedia'
     code = 'test'
-
-    login = True
     write = True

     def test_lock_unlock_topic(self):
@@ -210,9 +204,7 @@

     family = 'wikipedia'
     code = 'test'
-
-    login = True
-    write = -1
+    write = True

     def test_reply_to_locked_topic(self):
         """Test replying to locked topic (should raise exception)."""
@@ -236,8 +228,6 @@

     family = 'wikipedia'
     code = 'test'
-
-    login = True
     write = True

     def setUp(self):
diff --git a/tests/thanks_tests.py b/tests/thanks_tests.py
index 19e5ca9..5d81520 100755
--- a/tests/thanks_tests.py
+++ b/tests/thanks_tests.py
@@ -23,8 +23,6 @@

     family = 'wikipedia'
     code = 'test'
-
-    login = True
     write = True

     def test_thank_revision(self):
@@ -77,8 +75,7 @@

     family = 'wikipedia'
     code = 'test'
-
-    write = -1
+    write = True

     def test_bad_recipient(self):
         """Test that thanking a bad recipient causes an error."""

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1041541?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I31dd1a14df43d6ccc84371fe73908530b3d00aaa
Gerrit-Change-Number: 1041541
Gerrit-PatchSet: 5
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to