diff options
author | boris <boris@verhovs.ky> | 2019-08-06 13:34:58 -0700 |
---|---|---|
committer | boris <boris@verhovs.ky> | 2019-08-06 13:34:58 -0700 |
commit | 5f95dce95602921a70bfbc7d8de2f7712c5e4505 (patch) | |
tree | 681fb33747fc5a3be3ff747ccc9978207df69cb7 /doc/en/unittest.rst | |
parent | 75d0b899bbb56d6849e9d69d83a9426ed3f43f8b (diff) | |
download | pytest-5f95dce95602921a70bfbc7d8de2f7712c5e4505.tar.gz |
ran blacken-docs
Diffstat (limited to 'doc/en/unittest.rst')
-rw-r--r-- | doc/en/unittest.rst | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/doc/en/unittest.rst b/doc/en/unittest.rst index e8063c173..e5253af69 100644 --- a/doc/en/unittest.rst +++ b/doc/en/unittest.rst @@ -91,10 +91,12 @@ it from a unittest-style test:: import pytest + @pytest.fixture(scope="class") def db_class(request): class DummyDB: pass + # set a class attribute on the invoking test context request.cls.db = DummyDB() @@ -116,14 +118,15 @@ fixture definition:: import unittest import pytest + @pytest.mark.usefixtures("db_class") class MyTest(unittest.TestCase): def test_method1(self): assert hasattr(self, "db") - assert 0, self.db # fail for demo purposes + assert 0, self.db # fail for demo purposes def test_method2(self): - assert 0, self.db # fail for demo purposes + assert 0, self.db # fail for demo purposes The ``@pytest.mark.usefixtures("db_class")`` class-decorator makes sure that the pytest fixture function ``db_class`` is called once per class. @@ -193,11 +196,11 @@ creation of a per-test temporary directory:: import pytest import unittest - class MyTest(unittest.TestCase): + class MyTest(unittest.TestCase): @pytest.fixture(autouse=True) def initdir(self, tmpdir): - tmpdir.chdir() # change to pytest-provided temporary directory + tmpdir.chdir() # change to pytest-provided temporary directory tmpdir.join("samplefile.ini").write("# testdata") def test_method(self): |