Skip to content

PLONE_RESTAPI_DX_FIXTURE errors in Windows because of time.tzset() #2027

Description

@ewohnlich

I wrote some tests for my package using the PLONE_RESTAPI_DX_FIXTURE, but these fail because time.tzset() is not available in Windows. This is used plone.restapi.testing DateTimeFixture

To Reproduce

testing.py:

from plone.restapi.testing import PLONE_RESTAPI_DX_FIXTURE
RESTAPI_TESTING = FunctionalTesting(
    bases=(FIXTURE, WSGI_SERVER_FIXTURE, PLONE_RESTAPI_DX_FIXTURE),
    name="EntrezSiteLayer:RestAPITesting",
)

conftest(s):

globals().update(
    fixtures_factory((
        (FUNCTIONAL_TESTING, "functional"),
        (INTEGRATION_TESTING, "integration"),
        (RESTAPI_TESTING, "restapi"),
    ))
)

...

@pytest.fixture
def api_session(portal):
    session = RelativeSession(portal.absolute_url())

    session.headers.update({"Accept": "application/json"})
    session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD)
    return session

test:

def test_api_empty(self, api_session):
        response = api_session.get(
            url="/@publications/search",
        ).json()
        assert response["metadata"]["count"] == 0
        assert response["publications"] == []

Error

request = <SubRequest 'zope_layer_class_plone_restapi_testing_DATE_TIME_FIXTURE_2530063177104' for <Function test_api_empty>>, layer = <Layer 'plone.restapi.testing.DateTimeFixture'>

    def class_fixture(request, layer):
        state = request.session.zopelayer_state
        if layer not in state.current:
>           setup_layer(layer, request)

.\.venv\Lib\site-packages\zope\pytestlayer\fixture.py:69: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.\.venv\Lib\site-packages\zope\pytestlayer\fixture.py:40: in setup_layer
    layer.setUp()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <Layer 'plone.restapi.testing.DateTimeFixture'>

    def setUp(self):
        tz = "UTC"
        os.environ["TZ"] = tz
>       time.tzset()
        ^^^^^^^^^^
E       AttributeError: module 'time' has no attribute 'tzset'

.\.venv\Lib\site-packages\plone\restapi\testing.py:80: AttributeError

tzset is not available in Windows. My tests pass with this commented out. I am not sure of the intended behavior here, but if it can't be os independent would it be possible to make this conditional on os.name != 'nt'?

Additional details

Plone: 6.2.0
plone.restapi: 10.0.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions