.. versionchanged:: 4.1
Config files are now always interpreted as utf-8 instead of
the system default encoding.
+
+ .. versionchanged:: 4.4
+ The special variable ``__file__`` is available inside config
+ files, specifying the absolute path to the config file itself.
"""
- config = {}
+ config = {'__file__': os.path.abspath(path)}
with open(path, 'rb') as f:
exec_in(native_str(f.read()), config, config)
for name in config:
options = OptionParser()
options.define("port", default=80)
options.define("username", default='foo')
- options.parse_config_file(os.path.join(os.path.dirname(__file__),
- "options_test.cfg"))
- self.assertEquals(options.port, 443)
+ options.define("my_path")
+ config_path = os.path.join(os.path.dirname(__file__),
+ "options_test.cfg")
+ options.parse_config_file(config_path)
+ self.assertEqual(options.port, 443)
self.assertEqual(options.username, "李康")
+ self.assertEqual(options.my_path, config_path)
def test_parse_callbacks(self):
options = OptionParser()