# FAILED tests/test_network.py::test_connect - pytest.PytestUnraisableExceptionWarning: Exception ignored in: <socket.socket fd=5>
ResourceWarning: unclosed <socket.socket fd=5, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('127.0.0.1', 54321), raddr=('127.0.0.1', 8080)>

- **ID:** `python/pytest-warnings-as-errors-unclosed-socket`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

pytest is configured with filterwarnings = error, so ResourceWarning from an unclosed socket (e.g., a connection not closed in a fixture or test) is promoted to an error and fails the test.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 7.x | active | — | — |
| 8.x | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   import socket
import pytest

@pytest.fixture
def conn():
    s = socket.create_connection(('127.0.0.1', 8080))
    yield s
    s.close()

def test_connect(conn):
    ...
   ```
2. **** (90% success)
   ```
   from contextlib import closing

def test_connect():
    with closing(socket.create_connection(('127.0.0.1', 8080))) as s:
        ...
   ```

## Dead Ends

- **** — Hides real resource leaks in production code and can mask other warnings-as-errors that you do want to catch. (70% fail)
- **** — gc.collect() may run before the socket's __del__ or may not close the socket deterministically; the warning can still fire during interpreter shutdown. (65% fail)
