{"id":15688135,"url":"https://github.com/pdobacz/pytest.jl","last_synced_at":"2026-03-27T04:07:04.948Z","repository":{"id":213161316,"uuid":"67339113","full_name":"pdobacz/PyTest.jl","owner":"pdobacz","description":"Trying to give Julia pytest-like testing abilities","archived":false,"fork":false,"pushed_at":"2018-02-27T21:36:19.000Z","size":74,"stargazers_count":11,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-07T20:41:22.810Z","etag":null,"topics":["fixtures","julialang","pytest","testing"],"latest_commit_sha":null,"homepage":"","language":"Julia","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pdobacz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-09-04T10:41:04.000Z","updated_at":"2025-02-16T13:32:37.000Z","dependencies_parsed_at":"2023-12-19T01:42:20.556Z","dependency_job_id":null,"html_url":"https://github.com/pdobacz/PyTest.jl","commit_stats":null,"previous_names":["pdobacz/pytest.jl"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/pdobacz/PyTest.jl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pdobacz%2FPyTest.jl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pdobacz%2FPyTest.jl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pdobacz%2FPyTest.jl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pdobacz%2FPyTest.jl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pdobacz","download_url":"https://codeload.github.com/pdobacz/PyTest.jl/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pdobacz%2FPyTest.jl/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263283080,"owners_count":23442286,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fixtures","julialang","pytest","testing"],"created_at":"2024-10-03T17:55:13.954Z","updated_at":"2026-03-27T04:07:04.899Z","avatar_url":"https://github.com/pdobacz.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PyTest\n\n[![Build Status](https://travis-ci.org/pdobacz/PyTest.jl.svg?branch=master)](https://travis-ci.org/pdobacz/PyTest.jl)\n[![Coverage Status](https://coveralls.io/repos/github/pdobacz/PyTest.jl/badge.svg?branch=master)](https://coveralls.io/github/pdobacz/PyTest.jl?branch=master)\n\n[![PyTest](http://pkg.julialang.org/badges/PyTest_0.6.svg)](http://pkg.julialang.org/?pkg=PyTest)\n\nAt the moment, *PyTest.jl* allows for basic setup/teardown of test resources using [pytest](http://doc.pytest.org/en/latest/index.html#)-inspired approach with fixtures.\n\n**IMPORTANT NOTICE** Looking for packages which could use *PyTest.jl* to pivot further development!\n\n## Instalation\n\n```julia\nPkg.add(\"PyTest\")\n```\n\n## Example fixture use\n\nWhen in need of particular test resources: `needed_resource` and `needed_resource2` (which may depend on each other), you can setup fresh instances of the resources (i.e. test fixtures) as follows:\n\n```julia\nusing PyTest\nusing TestedModule\n\n@fixture function needed_resource()\n  # returns some needed_resource\nend\n\n@fixture function needed_resource2(needed_resource)\n  # needed_resource here will hold the former fixture!\n  # returns some other needed_resource2\nend\n\n@pytest function my_test(needed_resource, needed_resource2)\n  # test body using both resources\n  # (gets fresh instances of both resources for every @pytest invocation)\nend\n```\n\n**NOTE**: For combining `@pytest` with `Base.Test.@testset` see [here](https://github.com/pdobacz/PyTest.jl#using-with-base-test-testset).\n\nA more concrete example to shed more light:\n\n```julia\n@fixture function matrix_size()\n  return 1200\nend\n\n@fixture function random_numbers(matrix_size)\n  return randn(matrix_size)\nend\n\n@fixture function random_square_matrix(matrix_size)\n  return randn(matrix_size, matrix_size)\nend\n\n@pytest function test_multiplication(random_square_matrix, random_numbers, matrix_size)\n  result = random_square_matrix * random_numbers\n  @test size(result) == (matrix_size, )\nend\n```\n\nIf a resource needs teardown to be done after tests are over, use the `@yield` macro provided by [ResumableFunctions](https://github.com/BenLauwens/ResumableFunctions.jl) instead of returning in the fixture function:\n\n```julia\nusing ResumableFunctions\n\n@fixture function torndown()\n  @yield \"some result\"\n  # here do the teardown\n  # this will be called after a test using this completes\nend\n```\n\n`PyTest.jl` uses `Base.Test` (in its `v0.5` flavour -- `BaseTestNext`), so every `@pytest` is also a `@testset`. A description to `@testset` can be given as a name of the test function:\n\n```julia\n@pytest function test_one_equals_one()\n  @test 1 == 1\nend\n```\n\n**NOTE** the fully qualified name of this tests will be `path/to/testfile.jl/test_one_equals_one`, where the path is relative to directory containing `runtests.jl`.\n\n**NOTE** parametrization information is appended to the name of the test, if it uses parametrized fixtures\n\n**NOTE** you may want to wrap all your test in a `@testset` invocation, so that the tests are summarized properly\n\n**NOTE** for more about what _could potentially_ be achieved with `pytest`-style fixtures, see [`pytest` docs on Fixtures](http://doc.pytest.org/en/latest/fixture.html).\n\n## Parametrized fixtures\n\nFixtures can be parametrized. For any `@pytest` invocation that depends on parametrized fixtures, every possible combination of fixture parameters will be tried.\n\nIn a parametrized fixture, the value of a parameter is fetched using a special `request` fixture:\n\n```julia\n@fixture params=[1, 2] function integer_number(request)\n  return request.param\nend\n\n@fixture params=['a', 'c'] function some_character(request)\n  return request.param\nend\n\n@pytest function test_numbers_and_chars(integer_number, some_character)\n  println(integer_number, some_character)\nend\n```\n\nThis should print (among `Base.Test` summaries):\n```\n1a\n2a\n1c\n2c\n```\n\n## Example builtin fixture: `tempdir_fixture`\n\nAt this stage there is only one builtin fixture `tempdir_fixture` which provides a fresh temporary directory, created and torndown specifically for the particular test.\n\n```julia\nremember = \"\"\n@pytest function test_isdir(tempdir_fixture)\n  remember = tempdir_fixture\n  @test isdir(tempdir_fixture)\nend\n@test !(isdir(remember))\n```\n\n**NOTE** for more ideas on what builtin fixtures _could potentially_ offer, look in [`pytest` docs here](http://doc.pytest.org/en/latest/builtin.html#builtin-fixtures-function-arguments)\n\n## Using with Base Test `@testset`\n\nTo use *PyTest.jl* fixtures in tests using standard `Base.Test.@testset`, currently one needs to nest the invocations:\n\n```julia\n@testset [CustomTestSet] [option=val...] \"description $w, $v\" for w in ..., v in ...\n  @pytest function test_name(...)\n    ...\n  end\nend\n```\n\nSee #1.\n\n## Invoking tests using `PyTest/runner.jl`\n\nThere is an experimental option to select tests to be run in style similar to `pytest`. To use:\n\n```sh\n# navigate to a package root directory (one containing the standard test/runtests.jl)\ncd path/to/package\n# assuming julia is in PATH\n# this will run all tests as if test/runtests.jl was run\njulia path/to/PyTest/runner.jl\n# this will only pick a certain test or test file\njulia path/to/PyTest/runner.jl runtests.jl/some_top_level_test_name\njulia path/to/PyTest/runner.jl testsubdir/tests.jl\njulia path/to/PyTest/runner.jl testsubdir/tests.jl/particular_test1 testsubdir/tests.jl/particular_test2\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpdobacz%2Fpytest.jl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpdobacz%2Fpytest.jl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpdobacz%2Fpytest.jl/lists"}