| 192 | |
| 193 | |
| 194 | def test_import_string_provides_traceback(tmpdir, monkeypatch): |
| 195 | monkeypatch.syspath_prepend(str(tmpdir)) |
| 196 | # Couple of packages |
| 197 | dir_a = tmpdir.mkdir("a") |
| 198 | dir_b = tmpdir.mkdir("b") |
| 199 | # Totally packages, I promise |
| 200 | dir_a.join("__init__.py").write("") |
| 201 | dir_b.join("__init__.py").write("") |
| 202 | # 'aa.a' that depends on 'bb.b', which in turn has a broken import |
| 203 | dir_a.join("aa.py").write("from b import bb") |
| 204 | dir_b.join("bb.py").write("from os import a_typo") |
| 205 | |
| 206 | # Do we get all the useful information in the traceback? |
| 207 | with pytest.raises(ImportError) as baz_exc: |
| 208 | utils.import_string("a.aa") |
| 209 | traceback = "".join(str(line) for line in baz_exc.traceback) |
| 210 | assert "bb.py':1" in traceback # a bit different than typical python tb |
| 211 | assert "from os import a_typo" in traceback |
| 212 | |
| 213 | |
| 214 | def test_import_string_attribute_error(tmpdir, monkeypatch): |