forked from breatheco-de/apiv2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
79 additions
and
52 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
from typing import Generator | ||
from typing import Generator, Optional | ||
|
||
import pytest | ||
from faker import Faker as Fake | ||
|
||
__all__ = ['fake', 'Fake'] | ||
|
||
FAKE = Fake() | ||
|
||
@pytest.fixture(autouse=True) | ||
def fake(seed: Optional[int]) -> Generator[Fake, None, None]: | ||
f = Fake() | ||
f.seed_instance(seed) | ||
|
||
@pytest.fixture(scope='module') | ||
def fake() -> Generator[Fake, None, None]: | ||
return FAKE | ||
yield f |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import random | ||
from typing import Generator, Optional | ||
|
||
import pytest | ||
|
||
__all__ = ['seed', 'Seed', 'pytest_addoption', 'pytest_terminal_summary'] | ||
|
||
type Seed = Optional[int] | ||
SEED = random.randint(0, 2 ** 32 - 1) | ||
seed_used = None | ||
SEED_KEY = '_+* SEED *+_' | ||
END_KEY = '_+* END *+_' | ||
|
||
def pytest_addoption(parser: pytest.Parser): | ||
try: | ||
parser.addoption('--seed', action='store', default=None, type=int, help='Set the random seed for tests') | ||
except Exception: | ||
... | ||
|
||
|
||
def pytest_terminal_summary(terminalreporter, config: pytest.Config) -> None: | ||
... | ||
# if hasattr(config, END_KEY) is False: | ||
# setattr(config, END_KEY, True) | ||
# seed = getattr(config, SEED_KEY, None) | ||
# terminalreporter.write_sep("=", "Capy Core Summary") | ||
# terminalreporter.write_line(f"Seed: {seed}") | ||
|
||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def seed(request: pytest.FixtureRequest) -> Generator[Optional[int], None, None]: | ||
global SEED | ||
|
||
seed = request.config.getoption('--seed') | ||
if seed is None: | ||
seed = SEED | ||
|
||
# if hasattr(request.config, SEED_KEY) is False: | ||
# setattr(request.config, SEED_KEY, seed) | ||
|
||
yield seed | ||
print(f'Seed used: {seed}') |
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
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
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