enjoythecode / strate.gg

A hobby project dedicated to the play and exploration of various abstract strategy board games.
https://strate.gg
3 stars 0 forks source link

Server test breakage: `ResourceWarning: unclosed file` #66

Closed enjoythecode closed 1 year ago

enjoythecode commented 1 year ago

All server tests (e.g. with make test) fail with the same error. See example error below.

The issue seems to be that files remain open at some phase of test running, causing pytest to cause an exception.

../venv/lib/python3.8/site-packages/_pytest/runner.py:259: in <lambda>
    lambda: ihook(item=item, **kwds), when=when, reraise=reraise
../venv/lib/python3.8/site-packages/pluggy/_hooks.py:265: in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
../venv/lib/python3.8/site-packages/pluggy/_manager.py:80: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
../venv/lib/python3.8/site-packages/_pytest/unraisableexception.py:88: in pytest_runtest_call
    yield from unraisable_exception_runtest_hook()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def unraisable_exception_runtest_hook() -> Generator[None, None, None]:
        with catch_unraisable_exception() as cm:
            yield
            if cm.unraisable:
                if cm.unraisable.err_msg is not None:
                    err_msg = cm.unraisable.err_msg
                else:
                    err_msg = "Exception ignored in"
                msg = f"{err_msg}: {cm.unraisable.object!r}\n\n"
                msg += "".join(
                    traceback.format_exception(
                        cm.unraisable.exc_type,
                        cm.unraisable.exc_value,
                        cm.unraisable.exc_traceback,
                    )
                )
>               warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))
E               pytest.PytestUnraisableExceptionWarning: Exception ignored in: <_io.FileIO [closed]>
E
E               Traceback (most recent call last):
E                 File "/home/sinan/Projects.git/strate.gg/be/tests/integration/conftest.py", line 58, in create
E                   client.get("/", base_url="https://localhost", follow_redirects=True)
E               ResourceWarning: unclosed file <_io.BufferedReader name='/home/sinan/Projects.git/strate.gg/be/app/../client/index.html'>