sebageek / servefile

serve or receive files from shell via a small HTTP server
38 stars 10 forks source link

Error "tests/test_servefile.py::test_version_standalone FAILED" with Python 3.11 #25

Open hartwork opened 1 year ago

hartwork commented 1 year ago

Inline with Python 3.10 and earlier, when running the tests with Python 3.11, I get this error:

=============================================================================== FAILURES ===============================================================================
_______________________________________________________________________ test_version_standalone ________________________________________________________________________

run_servefile = <function run_servefile.<locals>._run_servefile at 0x7fe63f744540>

    def test_version_standalone(run_servefile):
        # test if servefile also works by calling servefile.py directly
>       _test_version(run_servefile, standalone=True)

run_servefile = <function run_servefile.<locals>._run_servefile at 0x7fe63f744540>

tests/test_servefile.py:158: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

run_servefile = <function run_servefile.<locals>._run_servefile at 0x7fe63f744540>, standalone = True

    def _test_version(run_servefile, standalone):
        # we expect the version on stdout (python3.4+) or stderr(python2.6-3.3)
        s = run_servefile('--version', standalone=standalone, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        s.wait()
        version = s.stdout.readline().decode().strip()

        # python2 is deprecated, but we still want our tests to run for it
        # CryptographyDeprecationWarnings get in the way for this
        if 'CryptographyDeprecationWarning' in version:
            s.stdout.readline()  # ignore "from x import y" line
            version = s.stdout.readline().decode().strip()

        # hardcode version as string until servefile is a module
>       assert version == 'servefile 0.5.3'
E       assert "/var/tmp/portage/www-servers/servefile-0.5.3-r1/work/servefile-0.5.3/servefile/servefile.py:14: DeprecationWarning: 'cgi' is deprecated and slated for removal in Python 3.13" == 'servefile 0.5.3'
E         - servefile 0.5.3
E         + /var/tmp/portage/www-servers/servefile-0.5.3-r1/work/servefile-0.5.3/servefile/servefile.py:14: DeprecationWarning: 'cgi' is deprecated and slated for removal in Python 3.13

run_servefile = <function run_servefile.<locals>._run_servefile at 0x7fe63f744540>
s          = <Popen: returncode: 0 args: ['/var/tmp/portage/www-servers/servefile-0.5.3-r...>
standalone = True
version    = ('/var/tmp/portage/www-servers/servefile-0.5.3-r1/work/servefile-0.5.3/servefile/servefile.py:14: '
 "DeprecationWarning: 'cgi' is deprecated and slated for removal in Python "
 '3.13')

tests/test_servefile.py:149: AssertionError
------------------------------------------------------------------------- Captured stdout call -------------------------------------------------------------------------
running /var/tmp/portage/www-servers/servefile-0.5.3-r1/work/servefile-0.5.3/servefile/servefile.py with args ['--version', '-p', '35751']

It seems that the output from the DeprecationWarning warning is breaking the test.

Would be cool to have that fixed before the next release. Thanks in advance! :pray:

sebageek commented 1 year ago

Cool, thanks for the tip, will have a look.

sebageek commented 1 year ago

Looks like cgi is deprecated and FieldStorage has no proper replacement in the standard library. See https://peps.python.org/pep-0594/#cgi

The proper replacement would apparently be multipart as an external dependency. Originally I intended to keep servefile with minimal dependencies. So my options are:

sebageek commented 1 year ago

As a first step I'll silence the deprecation warning so servefile works with python3.11.