Created
February 13, 2019 05:46
-
-
Save zhukovgreen/9657c49a64e07b16c17637a3fd7b6561 to your computer and use it in GitHub Desktop.
Using pytest fixtures factories with teardown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
@pytest.fixture(scope="function") | |
def fixture_arg(): | |
def _opening_file_with_freecad(file): | |
# opening a file in freecad | |
print(f"starting with file is {file}") | |
file = "opened" | |
print(f"file is {file}") | |
yield _opening_file_with_freecad | |
# teardown | |
file = "closed" | |
print(f"file is {file}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
============================= test session starts ============================== | |
platform linux -- Python 3.7.1, pytest-4.2.0, py-1.7.0, pluggy-0.8.1 | |
rootdir: /home/zhukovgreen/Dropbox/code/experiments/tests, inifile:collected 2 items | |
test_fixt_with_arg.py .starting with file is some freecad file path | |
file is opened | |
file is closed | |
.starting with file is some freecad file path | |
file is opened | |
file is closed | |
[100%] | |
=========================== 2 passed in 0.01 seconds =========================== | |
Process finished with exit code 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def test_fix_with_arg(fixture_arg): | |
fixture_arg("some freecad file path") | |
def test_fix_with_arg1(fixture_arg): | |
fixture_arg("some freecad file path") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment