Skip to content

Commit

Permalink
Block sockets for unit-tests (langchain-ai#4803)
Browse files Browse the repository at this point in the history
# Block usage of sockets during unit tests

Catch any tests that attempt to use the network.
  • Loading branch information
eyurtsev authored May 16, 2023
1 parent f7e3d97 commit c3b6129
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ lint lint_diff:
TEST_FILE ?= tests/unit_tests/

test:
poetry run pytest $(TEST_FILE)
poetry run pytest --disable-socket --allow-unix-socket $(TEST_FILE)

tests:
poetry run pytest $(TEST_FILE)
tests:
poetry run pytest --disable-socket --allow-unix-socket $(TEST_FILE)

extended_tests:
poetry run pytest --only-extended tests/unit_tests
poetry run pytest --disable-socket --allow-unix-socket --only-extended tests/unit_tests

test_watch:
poetry run ptw --now . -- tests/unit_tests
Expand Down
17 changes: 16 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ responses = "^0.22.0"
pytest-asyncio = "^0.20.3"
lark = "^1.1.5"
pytest-mock = "^3.10.0"
pytest-socket = "^0.6.0"

[tool.poetry.group.test_integration]
optional = true
Expand Down
9 changes: 9 additions & 0 deletions tests/unit_tests/test_pytest_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pytest
import pytest_socket
import requests


def test_socket_disabled() -> None:
"""This test should fail."""
with pytest.raises(pytest_socket.SocketBlockedError):
requests.get("https://www.example.com")

0 comments on commit c3b6129

Please sign in to comment.