Skip to content

app reset fails due to improper I/O #4312

@ReubenVandezande

Description

Description

My nicegui tests run with pytest leave .nfs files in the .nicegui folder and cause my tests to fail.

I run my nicegui tests on a system that produces .nfs files when a file is deleted before I/O is properly terminated. Annoyingly, these files cannot be deleted by the user and only get cleaned up after the process finishes execution. The only file in the cache is storage-user-*.json so I assume that is the file handle which gets closed improperly.

My workaround is to simply move the .nicegui cache folder to trick the app into behaving correctly.

@pytest.fixture
def user(user: User) -> User:
    yield user
    try:
        app.reset()
    except OSError:
        # This is necessary since once of the file handles opened
        # by nicegui isn't closed properly and leaves a .nfs file
        # We move the cache folder and then delete later.
        if list(app.storage.path.glob(".nfs*")):
            tmp_path = Path(".to_delete", '.nicegui')
            tmp_path.parent.mkdir(exist_ok=True)
            if tmp_path.exists():
                shutil.rmtree(tmp_path)

            shutil.move(app.storage.path, tmp_path)
        app.reset()

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions