Skip to content

Commit fa0350b

Browse files
committed
test that passes locally but will fail in CI
1 parent f4009bd commit fa0350b

File tree

3 files changed

+12
-32
lines changed

3 files changed

+12
-32
lines changed

posthog/client.py

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from dateutil.tz import tzutc
1212
from six import string_types
13+
import distro # For Linux OS detection
1314

1415
from posthog.consumer import Consumer
1516
from posthog.exception_capture import ExceptionCapture
@@ -38,55 +39,31 @@ def get_os_info():
3839
os_name = ""
3940
os_version = ""
4041

41-
# Windows
4242
if sys.platform.startswith("win"):
4343
os_name = "Windows"
4444
if hasattr(platform, "win32_ver"):
4545
win_version = platform.win32_ver()[0]
4646
if win_version:
4747
os_version = win_version
4848

49-
# macOS/Mac OS X
5049
elif sys.platform == "darwin":
5150
os_name = "Mac OS X"
5251
if hasattr(platform, "mac_ver"):
5352
mac_version = platform.mac_ver()[0]
5453
if mac_version:
5554
os_version = mac_version
5655

57-
# iOS (unlikely in standard Python but included for completeness)
58-
elif sys.platform == "ios":
59-
os_name = "iOS"
60-
# iOS version would need a specific approach
61-
62-
# Linux
6356
elif sys.platform.startswith("linux"):
6457
os_name = "Linux"
65-
if hasattr(platform, "linux_distribution"):
66-
# Deprecated in Python 3.8+
67-
try:
68-
linux_info = platform.linux_distribution()
69-
if linux_info[0] and linux_info[1]:
70-
os_version = linux_info[1]
71-
except:
72-
pass
73-
# For newer Python versions
74-
try:
75-
import distro
58+
linux_info = distro.info()
59+
if linux_info["version"]:
60+
os_version = linux_info["version"]
7661

77-
linux_info = distro.info()
78-
if linux_info["version"]:
79-
os_version = linux_info["version"]
80-
except ImportError:
81-
pass
82-
83-
# FreeBSD
8462
elif sys.platform.startswith("freebsd"):
8563
os_name = "FreeBSD"
8664
if hasattr(platform, "release"):
8765
os_version = platform.release()
8866

89-
# Other platforms
9067
else:
9168
os_name = sys.platform
9269
if hasattr(platform, "release"):
@@ -308,11 +285,13 @@ def capture(
308285
stacklevel=2,
309286
)
310287

311-
properties = properties or {}
288+
properties = {**(properties or {}), **system_context()}
289+
312290
require("distinct_id", distinct_id, ID_TYPES)
313291
require("properties", properties, dict)
314292
require("event", event, string_types)
315293

294+
316295
msg = {
317296
"properties": properties,
318297
"timestamp": timestamp,
@@ -347,7 +326,7 @@ def capture(
347326
extra_properties["$active_feature_flags"] = active_feature_flags
348327

349328
if extra_properties:
350-
msg["properties"] = {**extra_properties, **msg["properties"], **system_context()}
329+
msg["properties"] = {**extra_properties, **msg["properties"]}
351330

352331
return self._enqueue(msg, disable_geoip)
353332

posthog/test/test_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ def test_basic_capture(self):
5555
self.assertEqual(msg["properties"]["$lib"], "posthog-python")
5656
self.assertEqual(msg["properties"]["$lib_version"], VERSION)
5757
assert msg["properties"]["$python_runtime"] == "CPython"
58-
assert msg["properties"]["$python_version"] == "3.12.4"
59-
assert msg["properties"]["$os"] == "macOS"
60-
assert msg["properties"]["$os_version"] == "14.5.0"
58+
assert msg["properties"]["$python_version"] == "3.11.11"
59+
assert msg["properties"]["$os"] == "Mac OS X"
60+
assert msg["properties"]["$os_version"] == "15.3.1"
6161

6262
def test_basic_capture_with_uuid(self):
6363
client = self.client

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"monotonic>=1.5",
2121
"backoff>=1.10.0",
2222
"python-dateutil>2.1",
23+
"distro>=1.5.0", # Required for Linux OS detection in Python 3.9+
2324
]
2425

2526
extras_require = {

0 commit comments

Comments
 (0)