Mercurial > piecrust2
comparison tests/conftest.py @ 1028:63f118c773ee
tests: Prevent conflicts in later `pytest` versions.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 25 Dec 2017 23:05:49 -0800 |
parents | 45ad976712ec |
children | 2aa6174453c8 |
comparison
equal
deleted
inserted
replaced
1027:bcb7bd54d347 | 1028:63f118c773ee |
---|---|
17 pass | 17 pass |
18 | 18 |
19 | 19 |
20 def pytest_addoption(parser): | 20 def pytest_addoption(parser): |
21 parser.addoption( | 21 parser.addoption( |
22 '--log-debug', | 22 '--pc-log-debug', |
23 action='store_true', | 23 action='store_true', |
24 help="Sets the PieCrust logger to output debug info to stdout.") | 24 help="Sets the PieCrust logger to output debug info to stdout.") |
25 parser.addoption( | 25 parser.addoption( |
26 '--log-file', | 26 '--pc-log-file', |
27 help="Sets the PieCrust logger to write to a file.") | 27 help="Sets the PieCrust logger to write to a file.") |
28 parser.addoption( | 28 parser.addoption( |
29 '--mock-debug', | 29 '--pc-mock-debug', |
30 action='store_true', | 30 action='store_true', |
31 help="Prints contents of the mock file-system.") | 31 help="Prints contents of the mock file-system.") |
32 parser.addoption( | 32 parser.addoption( |
33 '--leave-mockfs', | 33 '--pc-leave-mockfs', |
34 action='store_true', | 34 action='store_true', |
35 help="Leave the contents of the mock file-system on disk.") | 35 help="Leave the contents of the mock file-system on disk.") |
36 | 36 |
37 | 37 |
38 def pytest_configure(config): | 38 def pytest_configure(config): |
39 if config.getoption('--log-debug'): | 39 if config.getoption('--pc-log-debug'): |
40 root_logger = logging.getLogger() | 40 root_logger = logging.getLogger() |
41 hdl = logging.StreamHandler(stream=sys.stdout) | 41 hdl = logging.StreamHandler(stream=sys.stdout) |
42 root_logger.addHandler(hdl) | 42 root_logger.addHandler(hdl) |
43 root_logger.setLevel(logging.DEBUG) | 43 root_logger.setLevel(logging.DEBUG) |
44 | 44 |
45 from .basefs import TestFileSystemBase | 45 from .basefs import TestFileSystemBase |
46 TestFileSystemBase._use_chef_debug = True | 46 TestFileSystemBase._use_chef_debug = True |
47 TestFileSystemBase._pytest_log_handler = hdl | 47 TestFileSystemBase._pytest_log_handler = hdl |
48 | 48 |
49 log_file = config.getoption('--log-file') | 49 log_file = config.getoption('--pc-log-file') |
50 if log_file: | 50 if log_file: |
51 hdl = logging.StreamHandler( | 51 hdl = logging.StreamHandler( |
52 stream=open(log_file, 'w', encoding='utf8')) | 52 stream=open(log_file, 'w', encoding='utf8')) |
53 logging.getLogger().addHandler(hdl) | 53 logging.getLogger().addHandler(hdl) |
54 | 54 |
55 if config.getoption('--leave-mockfs'): | 55 if config.getoption('--pc-leave-mockfs'): |
56 from .basefs import TestFileSystemBase | 56 from .basefs import TestFileSystemBase |
57 TestFileSystemBase._leave_mockfs = True | 57 TestFileSystemBase._leave_mockfs = True |
58 | 58 |
59 | 59 |
60 def pytest_collect_file(parent, path): | 60 def pytest_collect_file(parent, path): |
99 def is_theme_site(self): | 99 def is_theme_site(self): |
100 return self.spec.get('theme_config') is not None | 100 return self.spec.get('theme_config') is not None |
101 | 101 |
102 @property | 102 @property |
103 def mock_debug(self): | 103 def mock_debug(self): |
104 return bool(self.config.getoption('--mock-debug')) | 104 return bool(self.config.getoption('--pc-mock-debug')) |
105 | 105 |
106 def _prepareMockFs(self): | 106 def _prepareMockFs(self): |
107 fs = mock_fs() | 107 fs = mock_fs() |
108 | 108 |
109 # Suppress any formatting or layout so we can compare | 109 # Suppress any formatting or layout so we can compare |