Xqt added a comment.

  In T154281#8069774 <https://phabricator.wikimedia.org/T154281#8069774>, @rook 
wrote:
  
  > I see one more of these in tests/utils.py though I'm unclear about how this 
is run. It does not appear to run through pytest (I would update tox.ini with a 
specific file to test, this one doesn't match the *tests.py pattern and 
ignoring that doesn't get it to run regardless). How would one run just the 
tests in utils.py?
  
  `utils.py` is not a test file itself but a library module for tests. All test 
files are ending with "tests" and are collected in `tests.__init__.py`, 
utils.py uses assertRaises inside the contextmanager 
AssertAPIErrorContextManager. The contextmanager is used in aspects to 
implement the assertAPIError method which is used for tests found here 
<https://codesearch.wmcloud.org/pywikibot/?q=assertAPIError&i=nope&files=&excludeFiles=&repos=>.
 For example you can test the flow_thanks_tests as follows:
  
  1. login your bot on testwiki: `pwb login -site:wikipedia:test`
  2. set the environment variable `PYWIKIBOT_TEST_WRITE` to 1 to enable write 
tests
  3. run the test script loacally: `pwb -site:wikipedia:test flow_thanks_tests 
-v TestThankFlowPost.test_self_thank`
  
  The AssertAPIErrorContextManager contextmanager needs the exception message 
regex somehow e.g.:
  
    def __init__(self, code, info, msg, test_case, regex=None):
        """Create instance expecting the code and info."""
        self.code = code
        self.info = info
        self.msg = msg
        self.test_case = test_case
        self.regex = regex
    
    def __enter__(self):
        """Enter this context manager and the unittest's context manager."""
        if self.regex:
            self.cm = self.test_case.assertRaisesRegex(APIError, self.regex, 
msg=self.msg)
        else:
            self.cm = self.test_case.assertRaises(APIError, msg=self.msg)
        self.cm.__enter__()
        return self.cm

TASK DETAIL
  https://phabricator.wikimedia.org/T154281

EMAIL PREFERENCES
  https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: Xqt
Cc: rook, Ngwebecky96, Clockery, MtDu, Xqt, Sn1per, gerritbot, Aklapper, 
pywikibot-bugs-list, jayvdb, Gaurav24072002, Abhinay76, Annysah01, Rohitgeddam, 
Jyoo1011, JohnsonLee01, SHEKH, Dijkstra, Khutuck, Soda, Chaytanya, Zkhalido, 
JorisDarlingtonQuarshie, wiki-helenatxu, Viztor, Klein, Wenyi, Tks4Fish, 
Mh-3110, Bright1055, Lahi, Toppole69, Mine0901, harikiran, Jayprakash12345, 
SacredWKnight, JakeTheDeveloper, Tbscho, MayS, Beeyan, Mdupont, JJMC89, 
Dvorapa, xSavitar, Altostratus, Avicennasis, MuhammadShuaib, Tmalhotra, SimmeD, 
mys_721tx, Masti, Alchimista, Jay8g
_______________________________________________
pywikibot-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to