mrabarnett / mrab-regex

Other
450 stars 49 forks source link

2021.11.10: pytest is failing #448

Open kloczek opened 2 years ago

kloczek commented 2 years ago

I'm trying to package your module as an rpm package. So I'm using the typical build, install and test cycle used on building packages from non-root account.

Here is pytest output with one unit failing and some warnings as well:

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-regex-2021.11.10-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-regex-2021.11.10-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.12, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
benchmark: 3.4.1 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
Using --randomly-seed=1767319074
rootdir: /home/tkloczko/rpmbuild/BUILD/regex-2021.11.10
plugins: shutil-1.7.0, virtualenv-1.7.0, mock-3.6.1, cov-2.12.1, anyio-3.3.4, forked-1.3.0, xdist-2.3.0, flaky-3.7.0, tornasync-0.6.0.post2, console-scripts-1.2.0, trio-0.7.0, timeout-2.0.1, asyncio-0.16.0, freezegun-0.4.2, flake8-1.0.7, pyfakefs-4.5.3, hypothesis-6.29.3, benchmark-3.4.1, profiling-1.7.0, datadir-1.3.1, regressions-2.2.0, randomly-3.8.0, rerunfailures-9.1.1, yagot-0.5.0, requests-mock-1.9.3, django-4.5.1
collected 101 items

regex_3/test_regex.py F....................................................................................................                                          [100%]

================================================================================= FAILURES =================================================================================
________________________________________________________________________________ test_main _________________________________________________________________________________

    def test_main():
>       unittest.main(verbosity=2)

regex_3/test_regex.py:4449:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib64/python3.8/unittest/main.py:100: in __init__
    self.parseArgs(argv)
/usr/lib64/python3.8/unittest/main.py:133: in parseArgs
    self._main_parser.parse_args(argv[1:], self)
/usr/lib64/python3.8/argparse.py:1771: in parse_args
    self.error(msg % ' '.join(argv))
/usr/lib64/python3.8/argparse.py:2521: in error
    self.exit(2, _('%(prog)s: error: %(message)s\n') % args)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = ArgumentParser(prog='pytest', usage=None, description=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), status = 2
message = 'pytest: error: unrecognized arguments: -ra\n'

    def exit(self, status=0, message=None):
        if message:
            self._print_message(message, _sys.stderr)
>       _sys.exit(status)
E       SystemExit: 2

/usr/lib64/python3.8/argparse.py:2508: SystemExit
--------------------------------------------------------------------------- Captured stderr call ---------------------------------------------------------------------------
usage: pytest [-h] [-v] [-q] [--locals] [-f] [-c] [-b] [-k TESTNAMEPATTERNS]
              [tests [tests ...]]
pytest: error: unrecognized arguments: -ra
============================================================================= warnings summary =============================================================================
regex_3/test_regex.py:4277
  /home/tkloczko/rpmbuild/BUILD/regex-2021.11.10/regex_3/test_regex.py:4277: DeprecationWarning: invalid escape sequence \d
    self.assertEqual(regex.compile("(\d+ week|\d+ days)").split("7 days"), ['', '7 days', ''])

regex_3/test_regex.py:4278
  /home/tkloczko/rpmbuild/BUILD/regex-2021.11.10/regex_3/test_regex.py:4278: DeprecationWarning: invalid escape sequence \d
    self.assertEqual(regex.compile("(\d+ week|\d+ days)").split("10 days"), ['', '10 days', ''])

regex_3/test_regex.py:4280
  /home/tkloczko/rpmbuild/BUILD/regex-2021.11.10/regex_3/test_regex.py:4280: DeprecationWarning: invalid escape sequence \*
    self.assertEqual(regex.compile("[ ]* Name[ ]*\* ").search("  Name *"), None)

-- Docs: https://docs.pytest.org/en/stable/warnings.html
========================================================================= short test summary info ==========================================================================
FAILED regex_3/test_regex.py::test_main - SystemExit: 2
================================================================ 1 failed, 100 passed, 3 warnings in 1.60s =================================================================
mrabarnett commented 2 years ago

You didn't say how you got the source code, but judging from the "regex_3" it appears that you got it from the repository. The problem with that is that it contains sources for both Python 2 and Python 3.

I've started from the contents of the source distribution and it works for me on Windows, which is what I use.

kloczek commented 2 years ago

Yes I've used git tagged tar ball. Mixinx python 2.x and 3.xx code looks a bit odd especially if fact that python 2.x is now almost 2 years EOSed. I think that it would be better to just tag code tree (or branch it if it still necessary for something) which still supports python 2.x and remove all that code on the master to have clean code on next release?

kloczek commented 2 years ago

Just tested 2022.3.2 and looks like issie still is not ressolved.

kloczek commented 2 years ago

gentle ping 😋

kloczek commented 2 years ago

Just retested 2022.8.17 and looks like issue still is around ..

```console + PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-regex-2022.8.17-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-regex-2022.8.17-2.fc35.x86_64/usr/lib/python3.8/site-packages + /usr/bin/pytest -ra =========================================================================== test session starts ============================================================================ platform linux -- Python 3.8.13, pytest-7.1.3, pluggy-1.0.0 rootdir: /home/tkloczko/rpmbuild/BUILD/mrab-regex-2022.8.17 collected 101 items regex_3/test_regex.py ....................................................................................................F [100%] ================================================================================= FAILURES ================================================================================= ________________________________________________________________________________ test_main _________________________________________________________________________________ def test_main(): > unittest.main(verbosity=2) regex_3/test_regex.py:4448: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib64/python3.8/unittest/main.py:100: in __init__ self.parseArgs(argv) /usr/lib64/python3.8/unittest/main.py:133: in parseArgs self._main_parser.parse_args(argv[1:], self) /usr/lib64/python3.8/argparse.py:1771: in parse_args self.error(msg % ' '.join(argv)) /usr/lib64/python3.8/argparse.py:2521: in error self.exit(2, _('%(prog)s: error: %(message)s\n') % args) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = ArgumentParser(prog='pytest', usage=None, description=None, formatter_class=, conflict_handler='error', add_help=True), status = 2 message = 'pytest: error: unrecognized arguments: -ra\n' def exit(self, status=0, message=None): if message: self._print_message(message, _sys.stderr) > _sys.exit(status) E SystemExit: 2 /usr/lib64/python3.8/argparse.py:2508: SystemExit --------------------------------------------------------------------------- Captured stderr call --------------------------------------------------------------------------- usage: pytest [-h] [-v] [-q] [--locals] [-f] [-c] [-b] [-k TESTNAMEPATTERNS] [tests [tests ...]] pytest: error: unrecognized arguments: -ra ========================================================================= short test summary info ========================================================================== FAILED regex_3/test_regex.py::test_main - SystemExit: 2 ====================================================================== 1 failed, 100 passed in 1.02s ======================================================================= ```
kloczek commented 6 months ago

Only FTR: just tested 2024.4.16 and regex_3/test_regex.py::test_main still fails.

Here is pytest output: ```console + PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-regex-2024.4.16-2.fc37.x86_64/usr/lib64/python3.10/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-regex-2024.4.16-2.fc37.x86_64/usr/lib/python3.10/site-packages + /usr/bin/pytest -ra -m 'not network' ==================================================================================== test session starts ==================================================================================== platform linux -- Python 3.10.14, pytest-8.1.1, pluggy-1.4.0 benchmark: 4.0.0 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000) rootdir: /home/tkloczko/rpmbuild/BUILD/mrab-regex-2024.4.16 configfile: pyproject.toml plugins: mock-3.14.0, benchmark-4.0.0, timeout-2.3.1 collected 102 items regex_3/test_regex.py .....................................................................................................F [100%] ========================================================================================= FAILURES ========================================================================================== _________________________________________________________________________________________ test_main _________________________________________________________________________________________ def test_main(): > unittest.main(verbosity=2) regex_3/test_regex.py:4458: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib64/python3.10/unittest/main.py:100: in __init__ self.parseArgs(argv) /usr/lib64/python3.10/unittest/main.py:133: in parseArgs self._main_parser.parse_args(argv[1:], self) /usr/lib64/python3.10/argparse.py:1836: in parse_args self.error(msg % ' '.join(argv)) /usr/lib64/python3.10/argparse.py:2594: in error self.exit(2, _('%(prog)s: error: %(message)s\n') % args) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = ArgumentParser(prog='pytest', usage=None, description=None, formatter_class=, conflict_handler='error', add_help=True), status = 2 message = 'pytest: error: unrecognized arguments: -ra -m\n' def exit(self, status=0, message=None): if message: self._print_message(message, _sys.stderr) > _sys.exit(status) E SystemExit: 2 /usr/lib64/python3.10/argparse.py:2581: SystemExit ----------------------------------------------------------------------------------- Captured stderr call ------------------------------------------------------------------------------------ usage: pytest [-h] [-v] [-q] [--locals] [-f] [-c] [-b] [-k TESTNAMEPATTERNS] [tests ...] pytest: error: unrecognized arguments: -ra -m ================================================================================== short test summary info ================================================================================== FAILED regex_3/test_regex.py::test_main - SystemExit: 2 =============================================================================== 1 failed, 101 passed in 1.07s =============================================================================== ```
EpicWink commented 4 months ago

The root issue here is the test invocation: try one of the following:


There is a function in the test module called test_main, which Pytest thinks is a test to run. Unfortunately, it's not; it's simply the command-line entrypoint function, and it performs command-line argument parsing. This could be fixed by renaming the function to main.