Repository: cherrypy/cheroot (language: python)

Issue:
Pytest 7: test_high_number_of_file_descriptors causes next test to fail
❓ **I'm submitting a ...**
- [X] 🐞 bug report
- [ ] 🐣 feature request
- [ ] ❓ question about the decisions made in the repository

🐞 **Describe the bug. What is the current behavior?**
When upgrading to pytest 7, the test suite fails with an error for setting up the first test of test_ssl.py, which is usually run after `test_server.py::test_high_numer_of_file_descriptors`.


💡 **To Reproduce**
1. Install pytest >= 7.1.1
2. replace `--numprocesses=auto` in `pytest.ini` with 1 or delete the flag.
3. Run pytest
 

💡 **Expected behavior**
Successful test suite

📋 **Details**

<details>

```
abuild@skylab:~/rpmbuild/BUILD/cheroot-8.6.0> python3 -m pytest -x -n 1
================================================================================================================================= test session starts ==================================================================================================================================
platform linux -- Python 3.8.12, pytest-7.1.1, pluggy-1.0.0 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /home/abuild/rpmbuild/BUILD/cheroot-8.6.0, configfile: pytest.ini, testpaths: cheroot/test/
plugins: forked-1.3.0, xdist-2.5.0, mock-3.6.1
[gw0] linux Python 3.8.12 cwd: /home/abuild/rpmbuild/BUILD/cheroot-8.6.0
[gw0] Python 3.8.12 (default, Aug 31 2021, 01:23:42) [GCC]
gw0 [157]
scheduling tests via LoadScheduling

...
[gw0] [ 64%] PASSED cheroot/test/test_server.py::test_peercreds_unix_sock_with_lookup[file] 
cheroot/test/test_server.py::test_high_number_of_file_descriptors[1024] Exception ignored in: <socket.socket fd=1027, family=AddressFamily.AF_INET6, type=SocketKind.SOCK_STREAM, proto=6, laddr=('::1', 38954, 0, 0), raddr=('::1', 59583, 0, 0)>
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/_pytest/runner.py", line 136, in runtestprotocol
    item.funcargs = None  # type: ignore[attr-defined]
ResourceWarning: unclosed <socket.socket fd=1027, family=AddressFamily.AF_INET6, type=SocketKind.SOCK_STREAM, proto=6, laddr=('::1', 38954, 0, 0), raddr=('::1', 59583, 0, 0)>

[gw0] [ 65%] PASSED cheroot/test/test_server.py::test_high_number_of_file_descriptors[1024] 
cheroot/test/test_server.py::test_high_number_of_file_descriptors[2048] Exception ignored in: <socket.socket fd=2051, family=AddressFamily.AF_INET6, type=SocketKind.SOCK_STREAM, proto=6, laddr=('::1', 35316, 0, 0), raddr=('::1', 44913, 0, 0)>
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/_pytest/runner.py", line 136, in runtestprotocol
    item.funcargs = None  # type: ignore[attr-defined]
ResourceWarning: unclosed <socket.socket fd=2051, family=AddressFamily.AF_INET6, type=SocketKind.SOCK_STREAM, proto=6, laddr=('::1', 35316, 0, 0), raddr=('::1', 44913, 0, 0)>

[gw0] [ 66%] PASSED cheroot/test/test_server.py::test_high_number_of_file_descriptors[2048] 
cheroot/test/test_ssl.py::test_ssl_adapters[builtin] 
[gw0] [ 66%] ERROR cheroot/test/test_ssl.py::test_ssl_adapters[builtin] 

======================================================================================================================================== ERRORS ========================================================================================================================================
_____________________________________________________________________________________________________________________ ERROR at setup of test_ssl_adapters[builtin] _____________________________________________________________________________________________________________________
[gw0] linux -- Python 3.8.12 /usr/bin/python3

cls = <class '_pytest.runner.CallInfo'>, func = <function call_runtest_hook.<locals>.<lambda> at 0x7fd354fec160>, when = 'setup', reraise = (<class '_pytest.outcomes.Exit'>, <class 'KeyboardInterrupt'>)

    @classmethod
    def from_call(
        cls,
        func: "Callable[[], TResult]",
        when: "Literal['collect', 'setup', 'call', 'teardown']",
        reraise: Optional[
            Union[Type[BaseException], Tuple[Type[BaseException], ...]]
        ] = None,
    ) -> "CallInfo[TResult]":
        """Call func, wrapping the result in a CallInfo.
    
        :param func:
            The function to call. Called without arguments.
        :param when:
            The phase in which the function is called.
        :param reraise:
            Exception or exceptions that shall propagate if raised by the
            function, instead of being wrapped in the CallInfo.
        """
        excinfo = None
        start = timing.time()
        precise_start = timing.perf_counter()
        try:
>           result: Optional[TResult] = func()

cls        = <class '_pytest.runner.CallInfo'>
duration   = 0.00038953999955992913
excinfo    = <ExceptionInfo AssertionError('previous item was not torn down properly') tblen=6>
func       = <function call_runtest_hook.<locals>.<lambda> at 0x7fd354fec160>
precise_start = 5120.715909499
precise_stop = 5120.716299039
reraise    = (<class '_pytest.outcomes.Exit'>, <class 'KeyboardInterrupt'>)
result     = None
start      = 1648897978.8972251
stop       = 1648897978.8976173
when       = 'setup'

/usr/lib/python3.8/site-packages/_pytest/runner.py:338: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/lib/python3.8/site-packages/_pytest/runner.py:259: in <lambda>
    lambda: ihook(item=item, **kwds), when=when, reraise=reraise
        ihook      = <_HookCaller 'pytest_runtest_setup'>
        item       = <Function test_ssl_adapters[builtin]>
        kwds       = {}
/usr/lib/python3.8/site-packages/pluggy/_hooks.py:265: in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
        argname    = 'item'
        args       = ()
        firstresult = False
        kwargs     = {'item': <Function test_ssl_adapters[builtin]>}
        self       = <_HookCaller 'pytest_runtest_setup'>
/usr/lib/python3.8/site-packages/pluggy/_manager.py:80: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
        firstresult = False
        hook_name  = 'pytest_runtest_setup'
        kwargs     = {'item': <Function test_ssl_adapters[builtin]>}
        methods    = [<HookImpl plugin_name='nose', plugin=<module '_pytest.nose' from '/usr/lib/python3.8/site-packages/_pytest/nose.py'>>...=None>>, <HookImpl plugin_name='logging-plugin', plugin=<_pytest.logging.LoggingPlugin object at 0x7fd357f1a5e0>>, ...]
        self       = <_pytest.config.PytestPluginManager object at 0x7fd35dbb1b50>
/usr/lib/python3.8/site-packages/_pytest/runner.py:154: in pytest_runtest_setup
    item.session._setupstate.setup(item)
        item       = <Function test_ssl_adapters[builtin]>
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <_pytest.runner.SetupState object at 0x7fd357ecb220>, item = <Function test_ssl_adapters[builtin]>

    def setup(self, item: Item) -> None:
        """Setup objects along the collector chain to the item."""
        needed_collectors = item.listchain()
    
        # If a collector fails its setup, fail its entire subtree of items.
        # The setup is not retried for each item - the same exception is used.
        for col, (finalizers, exc) in self.stack.items():
>           assert col in needed_collectors, "previous item was not torn down properly"
E           AssertionError: previous item was not torn down properly

col        = <Module test_server.py>
exc        = None
finalizers = [<bound method Node.teardown of <Module test_server.py>>]
item       = <Function test_ssl_adapters[builtin]>
needed_collectors = [<Session cheroot-8.6.0 exitstatus=<ExitCode.OK: 0> testsfailed=0 testscollected=157>, <Package test>, <Module test_ssl.py>, <Function test_ssl_adapters[builtin]>]
self       = <_pytest.runner.SetupState object at 0x7fd357ecb220>

/usr/lib/python3.8/site-packages/_pytest/runner.py:482: AssertionError
--------------------------------------------------------------------------------------------- generated xml file: /home/abuild/rpmbuild/BUILD/cheroot-8.6.0/.test-results/pytest/test.xml ----------------------------------------------------------------------------------------------
================================================================================================================================= slowest 10 durations =================================================================================================================================
4.01s call     cheroot/test/test_conn.py::test_HTTP11_Timeout_after_request
3.43s call     cheroot/test/test_conn.py::test_keepalive_conn_management
2.00s call     cheroot/test/test_conn.py::test_HTTP11_Timeout[True]
2.00s call     cheroot/test/test_conn.py::test_HTTP11_Timeout[False]
1.04s call     cheroot/test/test_conn.py::test_invalid_selected_connection
0.60s call     cheroot/test/test_conn.py::test_598
0.60s call     cheroot/test/test_server.py::test_server_interrupt[RuntimeError]
0.60s call     cheroot/test/test_server.py::test_server_interrupt[OSError1]
0.60s call     cheroot/test/test_server.py::test_server_interrupt[OSError0]
0.60s call     cheroot/test/test_server.py::test_server_interrupt[KeyboardInterrupt]
=============================================================================================================================== short test summary info ================================================================================================================================
XFAIL cheroot/test/test_conn.py::test_Chunked_Encoding
  Headers from earlier request leak into the request line for a subsequent request, resulting in 400 instead of 413. See cherrypy/cheroot#69 for details.
XFAIL cheroot/test/test_conn.py::test_598
  Sometimes this test fails due to low timeout. Ref: https://github.com/cherrypy/cherrypy/issues/598
XFAIL cheroot/test/test_core.py::test_large_request
  https://github.com/cherrypy/cheroot/issues/106
ERROR cheroot/test/test_ssl.py::test_ssl_adapters[builtin] - AssertionError: previous item was not torn down properly
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! xdist.dsession.Interrupted: stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
================================================================================================================== 101 passed, 3 xfailed, 1 error in 63.11s (0:01:03) ==================================================================================================================
abuild@skylab:~/rpmbuild/BUILD/cheroot-8.6.0> 


```
</details>

📋 **Environment**
<!--
Please complete the following information:
-->
- Cheroot version: 6.8.0
- CherryPy version: N/A
- Python version: 3.8.12 (+ 3.9 + 3.10)
- OS: openSUSE Tumbleed Linux (Inside openbuildservive VM for rpmbuild)



Disable forked and unpin pytest
❓ **What kind of change does this PR introduce?**

* [ ] 🐞 bug fix
* [ ] 🐣 feature
* [ ] 📋 docs update
* [ ] 📋 tests/coverage improvement
* [ ] 📋 refactoring
* [ ] 💥 other

📋 **What is the related issue number (starting with `#`)**

<!-- Are there any issues opened that will be resolved by merging this change? -->
Resolves #<!-- issue number here -->

❓ **What is the current behavior?** (You can also link to an open issue here)



❓ **What is the new behavior (if this is a feature change)?**



📋 **Other information**:



📋 **Contribution checklist:**

(If you're a first-timer, check out
[this guide on making great pull requests][making a lovely PR])

* [ ] I wrote descriptive pull request text above
* [ ] I think the code is well written
* [ ] I wrote [good commit messages]
* [ ] I have [squashed related commits together][related squash] after
      the changes have been approved
* [ ] Unit tests for the changes exist
* [ ] Integration tests for the changes exist (if applicable)
* [ ] I used the same coding conventions as the rest of the project
* [ ] The new code doesn't generate linter offenses
* [ ] Documentation reflects the changes
* [ ] The PR relates to *only* one subject with a clear title
      and description in grammatically correct, complete sentences

[good commit messages]: http://chris.beams.io/posts/git-commit/
[making a lovely PR]: https://mtlynch.io/code-review-love/
[related squash]:
https://github.com/todotxt/todo.txt-android/wiki/Squash-All-Commits-Related-to-a-Single-Issue-into-a-Single-Commit

<!-- Reviewable:start -->
- - -
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/cherrypy/cheroot/681)
<!-- Reviewable:end -->

Tests failing when building locally (in typeguard)
When testing locally, I'm seeing this error:

```
 cheroot main @ tox
py: install_deps> .tox/py/bin/python -bb -E -s /Users/jaraco/code/cherrypy/cheroot/bin/pip-wrapper py /Users/jaraco/code/cherrypy/cheroot/requirements/ install -r requirements/tests.in
.pkg: install_requires> python -I -m pip install 'setuptools-scm>=7.0.0' 'setuptools>=34.4'
.pkg: _optional_hooks> python '/Users/jaraco/Library/Application Support/pipx/venvs/tox/lib/python3.12/site-packages/pyproject_api/_backend.py' True setuptools.build_meta
.pkg: get_requires_for_build_editable> python '/Users/jaraco/Library/Application Support/pipx/venvs/tox/lib/python3.12/site-packages/pyproject_api/_backend.py' True setuptools.build_meta
.pkg: install_requires_for_build_editable> python -I -m pip install 'setuptools_scm>=7.0.0' wheel
.pkg: build_editable> python '/Users/jaraco/Library/Application Support/pipx/venvs/tox/lib/python3.12/site-packages/pyproject_api/_backend.py' True setuptools.build_meta
py: install_package_deps> .tox/py/bin/python -bb -E -s /Users/jaraco/code/cherrypy/cheroot/bin/pip-wrapper py /Users/jaraco/code/cherrypy/cheroot/requirements/ install 'importlib-metadata; python_version < "3.8"' jaraco.functools 'more-itertools>=2.6'
py: install_package> .tox/py/bin/python -bb -E -s /Users/jaraco/code/cherrypy/cheroot/bin/pip-wrapper py /Users/jaraco/code/cherrypy/cheroot/requirements/ install --force-reinstall --no-deps /Users/jaraco/code/cherrypy/cheroot/.tox/.tmp/package/1/cheroot-11.0.0b1.dev27+g9d4de6b0-0.editable-py3-none-any.whl
py: commands_pre[0]> .tox/py/bin/python -bb -E -s -m OpenSSL.debug
pyOpenSSL: 24.1.0
cryptography: 42.0.5
cffi: 1.16.0
cryptography's compiled against OpenSSL: OpenSSL 3.2.1 30 Jan 2024
cryptography's linked OpenSSL: OpenSSL 3.2.1 30 Jan 2024
Python's OpenSSL: OpenSSL 3.2.1 30 Jan 2024
Python executable: /Users/jaraco/code/cherrypy/cheroot/.tox/py/bin/python
Python version: 3.12.2 (main, Feb  6 2024, 20:19:44) [Clang 15.0.0 (clang-1500.1.0.2.5)]
Platform: darwin
sys.path: ['/Users/jaraco/code/cherrypy/cheroot', '/opt/homebrew/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python312.zip', '/opt/homebrew/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12', '/opt/homebrew/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/lib-dynload', '/Users/jaraco/code/cherrypy/cheroot/.tox/py/lib/python3.12/site-packages']
py: commands[0]> .tox/py/bin/python -bb -E -s -m pytest --color=yes
/Users/jaraco/code/cherrypy/cheroot/.tox/py/lib/python3.12/site-packages/_pytest/config/__init__.py:318: PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
Plugin: helpconfig, Hook: pytest_cmdline_parse
ImportError: cannot import name 'Config' from 'pytest' (/Users/jaraco/code/cherrypy/cheroot/.tox/py/lib/python3.12/site-packages/pytest/__init__.py)
For more information see https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning
  config = pluginmanager.hook.pytest_cmdline_parse(
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/jaraco/code/cherrypy/cheroot/.tox/py/lib/python3.12/site-packages/pytest/__main__.py", line 5, in <module>
    raise SystemExit(pytest.console_main())
                     ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jaraco/code/cherrypy/cheroot/.tox/py/lib/python3.12/site-packages/_pytest/config/__init__.py", line 185, in console_main
    code = main()
           ^^^^^^
  File "/Users/jaraco/code/cherrypy/cheroot/.tox/py/lib/python3.12/site-packages/_pytest/config/__init__.py", line 143, in main
    config = _prepareconfig(args, plugins)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jaraco/code/cherrypy/cheroot/.tox/py/lib/python3.12/site-packages/_pytest/config/__init__.py", line 318, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jaraco/code/cherrypy/cheroot/.tox/py/lib/python3.12/site-packages/pluggy/_hooks.py", line 501, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jaraco/code/cherrypy/cheroot/.tox/py/lib/python3.12/site-packages/pluggy/_manager.py", line 119, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jaraco/code/cherrypy/cheroot/.tox/py/lib/python3.12/site-packages/pluggy/_callers.py", line 155, in _multicall
    teardown[0].send(outcome)
  File "/Users/jaraco/code/cherrypy/cheroot/.tox/py/lib/python3.12/site-packages/_pytest/helpconfig.py", line 100, in pytest_cmdline_parse
    config: Config = outcome.get_result()
                     ^^^^^^^^^^^^^^^^^^^^
  File "/Users/jaraco/code/cherrypy/cheroot/.tox/py/lib/python3.12/site-packages/pluggy/_result.py", line 99, in get_result
    raise exc.with_traceback(exc.__traceback__)
  File "/Users/jaraco/code/cherrypy/cheroot/.tox/py/lib/python3.12/site-packages/pluggy/_callers.py", line 102, in _multicall
    res = hook_impl.function(*args)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jaraco/code/cherrypy/cheroot/.tox/py/lib/python3.12/site-packages/_pytest/config/__init__.py", line 1003, in pytest_cmdline_parse
    self.parse(args)
  File "/Users/jaraco/code/cherrypy/cheroot/.tox/py/lib/python3.12/site-packages/_pytest/config/__init__.py", line 1283, in parse
    self._preparse(args, addopts=addopts)
  File "/Users/jaraco/code/cherrypy/cheroot/.tox/py/lib/python3.12/site-packages/_pytest/config/__init__.py", line 1172, in _preparse
    self.pluginmanager.load_setuptools_entrypoints("pytest11")
  File "/Users/jaraco/code/cherrypy/cheroot/.tox/py/lib/python3.12/site-packages/pluggy/_manager.py", line 414, in load_setuptools_entrypoints
    plugin = ep.load()
             ^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/metadata/__init__.py", line 205, in load
    module = import_module(match.group('module'))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "/Users/jaraco/code/cherrypy/cheroot/.tox/py/lib/python3.12/site-packages/_pytest/assertion/rewrite.py", line 170, in exec_module
    exec(co, module.__dict__)
  File "/Users/jaraco/code/cherrypy/cheroot/.tox/py/lib/python3.12/site-packages/typeguard/_pytest_plugin.py", line 7, in <module>
    from pytest import Config, Parser
ImportError: cannot import name 'Config' from 'pytest' (/Users/jaraco/code/cherrypy/cheroot/.tox/py/lib/python3.12/site-packages/pytest/__init__.py)
py: exit 1 (0.21 seconds) /Users/jaraco/code/cherrypy/cheroot> .tox/py/bin/python -bb -E -s -m pytest --color=yes pid=34147
  py: FAIL code 1 (8.42=setup[7.88]+cmd[0.33,0.21] seconds)
  evaluation failed :( (8.47 seconds)
```

I'm not sure why I'm not seeing the error in CI.
🧪 Stop using `pytest-forked`
This plugin is incompatible with Pytest 7+, it's difficult to fix upstream and there is no timeline for addressing that.

The patch also bumps the top version boundary of Pytest to 7.2 due to the pinned `pytest-cov` raising warnings.

Fixes #502
Resolves #511
Closes #680
Resolves #681

❓ **What kind of change does this PR introduce?**

* [ ] 🐞 bug fix
* [ ] 🐣 feature
* [ ] 📋 docs update
* [x] 📋 tests/coverage improvement
* [ ] 📋 refactoring
* [x] 💥 other

<!-- Reviewable:start -->
- - -
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/cherrypy/cheroot/703)
<!-- Reviewable:end -->



Discussion / hints:
That's an incompatibility of `pytest-forked` and pytest 7.

Same error was reported in https://github.com/agronholm/typeguard/issues/343.
I do see that pytest==6.2.5 is getting installed.
typeguard isn't being installed in CI, so that's probably why the issue isn't being encountered. I suspect typeguard is a recent dependency from inflect. CI is probably getting stale dependencies from somewhere.
Typeguard is coming from the dependency on `jaraco.text`:

```
jaraco.text==3.12.0
├── autocommand [required: Any, installed: 2.2.2]
├── inflect [required: Any, installed: 7.2.0]
│   ├── more-itertools [required: Any, installed: 10.2.0]
│   ├── typeguard [required: >=4.0.1, installed: 4.2.1]
```
Question is - should cheroot work to unpin the dependency on older pytest or fix the issue with typeguard?
pytest 6.2.5 is 2.5 years old.
The pin mentions #511 
Yes, pytest-forked is still unfixed: https://github.com/pytest-dev/pytest-forked/issues/67. That's the reason pytest is old. I've was considering removing the use of this plugin but never got to figuring out if it can be replaced.

I'm working towards making a stable v11.0.0 release (tried out the release pipeline through pre-release versions but the changelog needs to be polished a bit and then I'll release). Until it's released, I'd rather not add anything on top. Hoping to complete this in the next few days (ASAP really).
> Question is - should cheroot work to unpin the dependency on older pytest or fix the issue with typeguard?

That's the plan.
To give some context, the reason there's constraint files is that I figured that I value stability of the CI and transparency of the pin updates over testing against the latest versions. This also makes it easier on the PR authors since it's more predictable and easier to separate failures caused by PRs vs. failures caused by the broken CI. Since I implemented it, the CI here is exceptionally stable. But such constraints are sometimes need restrictions when incompatibilities cause problems. Those constraints are meant to be temporary and should be removed as soon as a solution is found.

Such old pins also start causing problems when other dependencies update and require newer versions of things. The recent example is https://github.com/cherrypy/cheroot/pull/656 where upgrading `inflect` which is transitive to us, makes pytest explode, supposedly because it needs v7 or v8 — I haven't yet looked closer, being focused on the release-related things.
@jaraco are you on x86_64 or ARM64? I suspect the latter. Currently, the lockfiles are only made for the former. So the `pip install` wrapper integrated in tox doesn't pick up the constraint file and you're getting a `pip install` invocation without a `-c` — essentially an unconstrained test dependency install.
Yes, ARM64 (macOS on Apple Silicon).


Fix patch:
diff --git a/docs/changelog-fragments.d/502.contrib.rst b/docs/changelog-fragments.d/502.contrib.rst
new file mode 120000
index 0000000000..c5e87d4ac3
--- /dev/null
+++ b/docs/changelog-fragments.d/502.contrib.rst
@@ -0,0 +1,1 @@
+703.contrib.rst
\ No newline at end of file
diff --git a/docs/changelog-fragments.d/511.contrib.rst b/docs/changelog-fragments.d/511.contrib.rst
new file mode 120000
index 0000000000..c5e87d4ac3
--- /dev/null
+++ b/docs/changelog-fragments.d/511.contrib.rst
@@ -0,0 +1,1 @@
+703.contrib.rst
\ No newline at end of file
diff --git a/docs/changelog-fragments.d/680.contrib.rst b/docs/changelog-fragments.d/680.contrib.rst
new file mode 120000
index 0000000000..c5e87d4ac3
--- /dev/null
+++ b/docs/changelog-fragments.d/680.contrib.rst
@@ -0,0 +1,1 @@
+703.contrib.rst
\ No newline at end of file
diff --git a/docs/changelog-fragments.d/681.contrib.rst b/docs/changelog-fragments.d/681.contrib.rst
new file mode 120000
index 0000000000..c5e87d4ac3
--- /dev/null
+++ b/docs/changelog-fragments.d/681.contrib.rst
@@ -0,0 +1,1 @@
+703.contrib.rst
\ No newline at end of file
diff --git a/docs/changelog-fragments.d/703.contrib.rst b/docs/changelog-fragments.d/703.contrib.rst
new file mode 100644
index 0000000000..16eb8b0d68
--- /dev/null
+++ b/docs/changelog-fragments.d/703.contrib.rst
@@ -0,0 +1,15 @@
+The test infrastructure has been updated to stop using
+the ``pytest-forked`` plugin
+-- by :user:`jaraco` and :user:`webknjaz`.
+
+This plugin was causing problems with upgrading to modern
+versions of Pytest and it is not going to be fixed anytime
+soon.
+
+It was used in a test that interacts with the system
+resource limits under \*NIX environments in hopes to isolate
+the side effects caused by the preparatory code.
+
+It is possible that this will have an effect on the test
+sessions and we may have to look for alternative solutions
+for test process isolation.


Test patch:
diff --git a/cheroot/test/test_server.py b/cheroot/test/test_server.py
index e2e5f788c7..3c39773119 100644
--- a/cheroot/test/test_server.py
+++ b/cheroot/test/test_server.py
@@ -400,15 +400,6 @@ def test_reuse_port(http_server, ip_addr, mocker):
     assert spy.spy_exception is None
 
 
-ISSUE511 = IS_MACOS
-
-
-if not IS_WINDOWS and not ISSUE511:
-    test_high_number_of_file_descriptors = pytest.mark.forked(
-        test_high_number_of_file_descriptors,
-    )
-
-
 @pytest.fixture
 def _garbage_bin():
     """Disable garbage collection when this fixture is in use."""
diff --git a/requirements/tests.in b/requirements/tests.in
index 7192fdff71..9b3f4070ed 100644
--- a/requirements/tests.in
+++ b/requirements/tests.in
@@ -34,18 +34,15 @@ pypytools
 
 pytest-clarity
 pytest-cov==2.12.0
-pytest-forked>=1.2.0; sys_platform != "win32"
 pytest-mock>=1.11.0
 pytest-rerunfailures
 pytest-sugar>=0.9.3
 pytest-watch==4.2.0
 pytest-xdist>=1.28.0
 
-# pytest-forked is currently incompatible with pytest 7
-# Refs:
-# * https://github.com/cherrypy/cheroot/issues/511
-# * https://github.com/pytest-dev/pytest-forked/issues/67
-pytest >= 4.6.6, < 7
+# pytest 7.2 introduces deprecations triggered by pytest-cov
+# * https://github.com/cherrypy/cheroot/issues/682
+pytest >= 7, <7.2
 
 # HTTP over UNIX socket
 requests-unixsocket