Editing
Development/Testing
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Fixtures == === Factory fixtures for data objects === When tests need multiple instances with variations, use factory fixtures: <syntaxhighlight lang="python"> @pytest.fixture def make_legislation_article(): """Factory: creates LegislationArticle instances with sensible defaults.""" def _make( article_id: str = "fr.legiarti000006436298", article_number: str = "1240", code_name: str = "code civil", is_in_force: bool = True, **overrides, ) -> LegislationArticle: defaults = { "article_id": article_id, "article_number": article_number, "code_name": code_name, "is_in_force": is_in_force, "html_content": "<p>Tout fait quelconque de l'homme...</p>", "plain_text_content": "Tout fait quelconque de l'homme...", } defaults.update(overrides) return LegislationArticle(**defaults) return _make </syntaxhighlight> === Real data fixtures === Test fixtures use '''real files''' from public institutional data sources (DILA, Judilibre, EUR-Lex). Not invented mocks. This is consistent with the project's commitment to transparency and auditability. <syntaxhighlight lang="python"> FIXTURES_DIR = Path(__file__).parent / "fixtures" @pytest.fixture def sample_legi_article_path() -> Path: """Real LEGI XML article: article 1240 du code civil.""" return FIXTURES_DIR / "fr.legiarti000006436298.xml" @pytest.fixture def sample_jade_decision_path() -> Path: """Real JADE XML decision: CE, 13 dec 2022, n 462274.""" return FIXTURES_DIR / "fr.cetatext000046783006.xml" </syntaxhighlight> === Session-scoped fixtures for expensive resources === <syntaxhighlight lang="python"> @pytest.fixture(scope="session") def database_connection(): """PostgreSQL connection via testcontainers. Shared across all tests in session.""" with PostgresContainer("postgres:17") as postgres: pool = ConnectionPool(postgres.get_connection_url()) yield pool pool.close() </syntaxhighlight>
Summary:
Please note that all contributions to Dura Lex Wiki are considered to be released under the Creative Commons Attribution-ShareAlike (see
Dura Lex Wiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
Edit source
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Tools
What links here
Related changes
Page information