Skip to content

Commit 0bbf9f4

Browse files
Update the test for the API key input.
1 parent 46ff501 commit 0bbf9f4

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="ip2location-io",
8-
version="1.0.3",
8+
version="1.0.4",
99
author="IP2Location",
1010
author_email="support@ip2location.com",
1111
description="This SDK provides users with the ability to perform IP geolocation lookup and domain WHOIS lookup through a web service.",

tests/conftest.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,38 @@
11
import pytest
2+
import os
23

3-
@pytest.fixture(scope = 'module')
4-
def global_data():
5-
return {'apikey': "YOUR_API_KEY"}
4+
def pytest_addoption(parser):
5+
"""
6+
Add a command-line option to pytest to pass the API key.
7+
"""
8+
parser.addoption(
9+
"--apikey",
10+
action="store",
11+
default=None,
12+
help="API Key for IP2Location.io Python tests"
13+
)
14+
15+
@pytest.fixture(scope="session")
16+
def global_data(request):
17+
"""
18+
Fixture to provide global test data, including the API key.
19+
20+
The API key can be passed as a command-line argument or through an
21+
environment variable. Command-line argument takes precedence.
22+
"""
23+
# First, try to get the API key from the command-line argument
24+
api_key = request.config.getoption("--apikey")
25+
26+
# If no API key is provided via command line, fallback to environment variable
27+
if not api_key:
28+
api_key = os.getenv("IP2LOCATION_API_KEY")
29+
30+
# If neither command-line argument nor environment variable is set, raise an error
31+
if not api_key:
32+
pytest.fail("API key is not set. Pass it via the --apikey argument or set the IP2LOCATION_API_KEY environment variable.")
33+
34+
# Return the global data containing the API key
35+
return {
36+
"apikey": api_key,
37+
# Add any other global data as needed
38+
}

0 commit comments

Comments
 (0)