Skip to content
Discussion options

You must be logged in to vote

This is not a Typer's issue..

You can solve this by re-importing the app on every test:

import helloworld.main

...
def test_list_databases():
    importlib.reload(helloworld.main)
    result = runner.invoke(helloworld.main.app, ...)
    ...
Working code example

helloworld/main.py

from functools import cached_property

import typer

class DatabaseManager:
    @cached_property
    def databases(self) -> list[str]:
        print(">> Creating databases list")
        return ["default-db"]

    def create(self, name: str) -> None:
        print(f">> Creating database {name}")
        self.databases.append(name)

manager = DatabaseManager()
app = typer.Typer()

@app.command()
def list_databases(…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@WilliamDEdwards
Comment options

Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
4 participants
Converted from issue

This discussion was converted from issue #364 on September 17, 2025 19:43.