Skip to content

Commit

Permalink
test: ensure no network calls during tests (#12939)
Browse files Browse the repository at this point in the history
* test: ensure no network calls during tests

Prevent accidental inclusion of network calls to anywhere we don't
expect.

Signed-off-by: Mike Fiedler <miketheman@gmail.com>

* test: CI doesn't use docker-compose names

* test: allow local ipv6 too

Signed-off-by: Mike Fiedler <miketheman@gmail.com>

* test: pass dummy credentials to boto session

If not passed, `botocore` will try to look them up from instance
metadata and make a remote call - even if they are invalid.

Signed-off-by: Mike Fiedler <miketheman@gmail.com>

---------

Signed-off-by: Mike Fiedler <miketheman@gmail.com>
  • Loading branch information
miketheman authored Feb 6, 2023
1 parent 186180c commit 96b8daf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ module = [
ignore_missing_imports = true

[tool.pytest.ini_options]
addopts = "--disable-socket --allow-hosts='localhost,::1,stripe'"
norecursedirs = ['build', 'dist', 'node_modules', '*.egg-info', '.state requirements']
markers = [
'unit: Quick running unit tests which test small units of functionality.',
Expand Down
1 change: 1 addition & 0 deletions requirements/tests.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ freezegun
pretend
pytest>=3.0.0
pytest-postgresql>=3.1.3,<4.0.0
pytest-socket
responses>=0.5.1
webtest
# Until resolved https://github.com/googleapis/python-bigquery/issues/1435
Expand Down
5 changes: 5 additions & 0 deletions requirements/tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,15 @@ pytest==7.2.1 \
# via
# -r requirements/tests.in
# pytest-postgresql
# pytest-socket
pytest-postgresql==3.1.3 \
--hash=sha256:05b87a192741511f5171e0300689a531a2a48b4483c69ae2b5f565d3e429b1d5 \
--hash=sha256:3649bcac5a0cd0d2cc1470a1087739990d402e2e910d53265ac486321a833898
# via -r requirements/tests.in
pytest-socket==0.6.0 \
--hash=sha256:363c1d67228315d4fc7912f1aabfd570de29d0e3db6217d61db5728adacd7138 \
--hash=sha256:cca72f134ff01e0023c402e78d31b32e68da3efdf3493bf7788f8eba86a6824c
# via -r requirements/tests.in
python-dateutil==2.8.2 \
--hash=sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86 \
--hash=sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/packaging/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ def test_basic_init(self):
assert storage.bucket is bucket

def test_create_service(self):
session = boto3.session.Session()
session = boto3.session.Session(
aws_access_key_id="foo", aws_secret_access_key="bar"
)
request = pretend.stub(
find_service=pretend.call_recorder(lambda name: session),
registry=pretend.stub(settings={"files.bucket": "froblob"}),
Expand Down Expand Up @@ -475,7 +477,9 @@ def test_verify_service(self):
assert verifyClass(IDocsStorage, S3DocsStorage)

def test_create_service(self):
session = boto3.session.Session()
session = boto3.session.Session(
aws_access_key_id="foo", aws_secret_access_key="bar"
)
request = pretend.stub(
find_service=pretend.call_recorder(lambda name: session),
registry=pretend.stub(settings={"docs.bucket": "froblob"}),
Expand Down

0 comments on commit 96b8daf

Please sign in to comment.