Skip to content

Commit

Permalink
Use a random available port number in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vaclav-2012 committed Dec 5, 2020
1 parent c4c9fe7 commit 9f1bde3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ We follow [Semantic Versions](https://semver.org/).

- Update dependencies
- Replace `dotty-dict` with `scalpl` to avoid compatibility issues on Windows 10 with Japanese locale
- Use a random port number for testing the HTTP server (to ensure the port is available)


## Version 0.1.7
Expand Down
12 changes: 11 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""

import os
import socket
from datetime import datetime
from typing import Optional
from unittest import mock
Expand All @@ -21,14 +22,23 @@

TEST_ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
HTTP_SERVER_HOSTNAME = "127.0.0.1"
HTTP_SERVER_PORT = 65000

OAUTH_CODE = "anime_girls_are_cute"
REFRESH_TOKEN = "moe_moe_kyun" # noqa: S105

TEST_IMAGE_URL = "https://raw.githubusercontent.com/slow-start-fans/slow-start-rewatch/master/assets/happy_shion.gif" # noqa: E501


def find_free_tcp_port() -> int:
"""Return random available port."""
with socket.socket() as tcp:
tcp.bind((HTTP_SERVER_HOSTNAME, 0))
return tcp.getsockname()[1]


HTTP_SERVER_PORT = find_free_tcp_port()


class MockConfig(Config):
"""
Simplified version of the Config class.
Expand Down

0 comments on commit 9f1bde3

Please sign in to comment.