Use fixtures in test_process_runner.py
This commit is contained in:
parent
5f7e886310
commit
58745a0eb4
|
@ -1,22 +1,26 @@
|
|||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
from monkey_island.cc.setup.mongo_process_runner import MongoDbRunner
|
||||
|
||||
TEST_DIR_NAME = "test_dir"
|
||||
|
||||
def test_create_db_dir(monkeypatch, tmpdir):
|
||||
test_dir_name = "test_dir"
|
||||
monkeypatch.setattr("monkey_island.cc.setup.mongo_process_runner.DB_DIR_NAME", test_dir_name)
|
||||
expected_path = os.path.join(tmpdir, test_dir_name)
|
||||
|
||||
@pytest.fixture
|
||||
def expected_path(monkeypatch, tmpdir):
|
||||
monkeypatch.setattr("monkey_island.cc.setup.mongo_process_runner.DB_DIR_NAME", TEST_DIR_NAME)
|
||||
expected_path = os.path.join(tmpdir, TEST_DIR_NAME)
|
||||
return expected_path
|
||||
|
||||
|
||||
def test_create_db_dir(monkeypatch, tmpdir, expected_path):
|
||||
db_path = MongoDbRunner(tmpdir, tmpdir)._create_db_dir()
|
||||
assert os.path.isdir(expected_path)
|
||||
assert db_path == expected_path
|
||||
|
||||
|
||||
def test_create_db_dir__already_created(monkeypatch, tmpdir):
|
||||
test_dir_name = "test_dir"
|
||||
monkeypatch.setattr("monkey_island.cc.setup.mongo_process_runner.DB_DIR_NAME", test_dir_name)
|
||||
expected_path = os.path.join(tmpdir, test_dir_name)
|
||||
def test_create_db_dir__already_created(monkeypatch, tmpdir, expected_path):
|
||||
os.mkdir(expected_path)
|
||||
|
||||
db_path = MongoDbRunner(tmpdir, tmpdir)._create_db_dir()
|
||||
|
|
Loading…
Reference in New Issue