Skip to content

Conversation

@euri10
Copy link
Collaborator

@euri10 euri10 commented Oct 28, 2025

Description

  • put the code-block in their own quickstart_# files and use literalinclude in the quickstart.rst
  • add /docs/examples/quickstart to pytest discover path
  • add a test on each block, test that wont be shown in docs thanks to lines and dedent directives

Closes

fixes #167

@euri10 euri10 changed the title docs: use literalinclude instead of code blocks on quickstart docs: use literalinclude instead of code-block on quickstart Oct 28, 2025
@euri10
Copy link
Collaborator Author

euri10 commented Oct 28, 2025

@cofin I just moved things around, are examples folder in the docs tested somehow, I didnt take the time to investigate but I'm sure you'll know :)

@euri10 euri10 marked this pull request as ready for review October 29, 2025 09:30
@euri10
Copy link
Collaborator Author

euri10 commented Oct 30, 2025

re-reading this after i'm on other pages I realize that for instance we could do differently:

current option1:

from sqlspec import SQLSpec
from sqlspec.adapters.sqlite import SqliteConfig

# Create SQLSpec instance and configure database
db_manager = SQLSpec()
db = db_manager.add_config(SqliteConfig(pool_config={"database": ":memory:"}))

# Execute a query
with db_manager.provide_session(db) as session:
    result = session.execute("SELECT 'Hello, SQLSpec!' as message")
    print(result.get_first())  # {'message': 'Hello, SQLSpec!'}


def test_quickstart_1() -> None:
    assert result.get_first() == {"message": "Hello, SQLSpec!"}

could be option2:

def test_quickstart_1() -> None:
    from sqlspec import SQLSpec
    from sqlspec.adapters.sqlite import SqliteConfig

    # Create SQLSpec instance and configure database 
    db_manager = SQLSpec()
    db = db_manager.add_config(SqliteConfig(pool_config={"database": ":memory:"}))

    # Execute a query
    with db_manager.provide_session(db) as session:
        result = session.execute("SELECT 'Hello, SQLSpec!' as message")
    print(result.get_first())  # {'message': 'Hello, SQLSpec!'}
    assert result.get_first() == {"message": "Hello, SQLSpec!"}

and we use dedent like in the async test on this pr, idk which one is better:

  • for the end user he'll see the same output in docs
  • for maintenance it means just write a test for an example, I think I prefer option 2, wdyt @cofin ?

@cofin
Copy link
Member

cofin commented Oct 31, 2025

  • for the end user he'll see the same output in docs
  • for maintenance it means just write a test for an example, I think I prefer option 2, wdyt @cofin ?

If there's no change in the user output, I definitely think that a single function is much easier to maintain here. I'd go with option 2 as well.

cofin and others added 6 commits November 3, 2025 19:37
- Introduced a new fixture `quickstart_postgres_env` to set up the Postgres environment for the documentation quickstart examples.
- The fixture uses `pytest-databases` to configure the necessary environment variables for connecting to the Postgres service.
- This setup is applied automatically for the test session, ensuring a consistent testing environment.
@cofin cofin changed the title docs: use literalinclude instead of code-block on quickstart docs: use 'literalinclude' instead of 'code-block' on quickstart Nov 10, 2025
@cofin cofin changed the title docs: use 'literalinclude' instead of 'code-block' on quickstart docs: use literalinclude instead of code-block on quickstart Nov 10, 2025
@cofin cofin merged commit 3061f72 into litestar-org:main Nov 10, 2025
23 of 27 checks passed
@euri10 euri10 deleted the docs_quickstart branch November 10, 2025 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

quickstart.rst

2 participants