def test_clock_invalid_timezone(fake_qtile, monkeypatch, fake_window, caplog):
    """test clock widget with invalid timezone (and no pytz or dateutil modules)"""

    class FakeDateutilTZ:
        @classmethod
        def tz(cls):
            return cls

        @classmethod
        def gettz(cls, val):
            return None

    # pytz and dateutil must not be in the sys.modules dict...
    monkeypatch.delitem(sys.modules, "pytz")
    monkeypatch.delitem(sys.modules, "dateutil")

    # Set up references to pytz and dateutil so we know these aren't being used
    # If they're called, the widget would try to run None(self.timezone) which
    # would raise an exception
    clock.pytz = None
    clock.dateutil = FakeDateutilTZ

    # Fake datetime module just adds the timezone value to the time
    clk2 = clock.Clock(timezone="1")

    fakebar = FakeBar([clk2], window=fake_window)
    clk2._configure(fake_qtile, fakebar)

    # An invalid timezone results in a log message
    assert (
        "Clock widget can not infer its timezone from a string without pytz or dateutil."
        in caplog.text
    )
test clock widget with invalid timezone (and no pytz or dateutil modules)
test/widgets/test_clock.py