Added a console option to specify the encoding to use for doctest files. Defaults to UTF-8.
This commit is contained in:
		
							parent
							
								
									36eb5b36d1
								
							
						
					
					
						commit
						ed977513ec
					
				|  | @ -43,6 +43,10 @@ def pytest_addoption(parser): | |||
|         action="store_true", default=False, | ||||
|         help="ignore doctest ImportErrors", | ||||
|         dest="doctest_ignore_import_errors") | ||||
|     group.addoption("--doctest-encoding", | ||||
|         type=str.lower, default="utf-8", | ||||
|         help="choose the encoding to use for doctest files", | ||||
|         dest="doctestencoding") | ||||
| 
 | ||||
| 
 | ||||
| def pytest_collect_file(path, parent): | ||||
|  | @ -171,7 +175,7 @@ class DoctestTextfile(pytest.Module): | |||
| 
 | ||||
|         # inspired by doctest.testfile; ideally we would use it directly, | ||||
|         # but it doesn't support passing a custom checker | ||||
|         text = self.fspath.read() | ||||
|         text = self.fspath.read_text(self.config.getoption("doctestencoding")) | ||||
|         filename = str(self.fspath) | ||||
|         name = self.fspath.basename | ||||
|         globs = {'__name__': '__main__'} | ||||
|  |  | |||
|  | @ -11,6 +11,13 @@ can change the pattern by issuing:: | |||
| on the command line. Since version ``2.9``, ``--doctest-glob`` | ||||
| can be given multiple times in the command-line. | ||||
| 
 | ||||
| You can specify the encoding that will be used for those doctest files | ||||
| using the ``--doctest-encoding`` command line option:: | ||||
| 
 | ||||
|     pytest --doctest-encoding='ascii' | ||||
| 
 | ||||
| The default encoding is UTF-8. | ||||
| 
 | ||||
| You can also trigger running of doctests | ||||
| from docstrings in all python modules (including regular | ||||
| python test modules):: | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue