---
source: crates/ruff_linter/src/rules/pyupgrade/mod.rs
---
UP026 [*] `mock` is deprecated, use `unittest.mock`
 --> UP026.py:3:12
  |
1 | # Error (`from unittest import mock`)
2 | if True:
3 |     import mock
  |            ^^^^
4 |
5 | # Error (`from unittest import mock`)
  |
help: Import from `unittest.mock` instead
  |
2 | if True:
  -     import mock
3 +     from unittest import mock
4 |
  |

UP026 [*] `mock` is deprecated, use `unittest.mock`
 --> UP026.py:7:12
  |
5 | # Error (`from unittest import mock`)
6 | if True:
7 |     import mock, sys
  |            ^^^^
8 |
9 | # Error (`from unittest.mock import *`)
  |
help: Import from `unittest.mock` instead
  |
6 | if True:
  -     import mock, sys
7 +     import sys
8 +     from unittest import mock
9 |
  |

UP026 [*] `mock` is deprecated, use `unittest.mock`
  --> UP026.py:11:5
   |
 9 | # Error (`from unittest.mock import *`)
10 | if True:
11 |     from mock import *
   |     ^^^^^^^^^^^^^^^^^^
12 |
13 | # Error (`from unittest import mock`)
   |
help: Import from `unittest.mock` instead
   |
10 | if True:
   -     from mock import *
11 +     from unittest.mock import *
12 |
   |

UP026 [*] `mock` is deprecated, use `unittest.mock`
  --> UP026.py:14:8
   |
13 | # Error (`from unittest import mock`)
14 | import mock.mock
   |        ^^^^^^^^^
15 |
16 | # Error (`from unittest import mock`)
   |
help: Import from `unittest.mock` instead
   |
13 | # Error (`from unittest import mock`)
   - import mock.mock
14 + from unittest import mock
15 |
   |

UP026 [*] `mock` is deprecated, use `unittest.mock`
  --> UP026.py:17:20
   |
16 | # Error (`from unittest import mock`)
17 | import contextlib, mock, sys
   |                    ^^^^
18 |
19 | # Error (`from unittest import mock`)
   |
help: Import from `unittest.mock` instead
   |
16 | # Error (`from unittest import mock`)
   - import contextlib, mock, sys
17 + import contextlib, sys
18 + from unittest import mock
19 |
   |

UP026 [*] `mock` is deprecated, use `unittest.mock`
  --> UP026.py:20:8
   |
19 | # Error (`from unittest import mock`)
20 | import mock, sys
   |        ^^^^
21 | x = "This code should be preserved one line below the mock"
   |
help: Import from `unittest.mock` instead
   |
19 | # Error (`from unittest import mock`)
   - import mock, sys
20 + import sys
21 + from unittest import mock
22 | x = "This code should be preserved one line below the mock"
   |

UP026 [*] `mock` is deprecated, use `unittest.mock`
  --> UP026.py:24:1
   |
23 | # Error (`from unittest import mock`)
24 | from mock import mock
   | ^^^^^^^^^^^^^^^^^^^^^
25 |
26 | # Error (keep trailing comma)
   |
help: Import from `unittest.mock` instead
   |
23 | # Error (`from unittest import mock`)
   - from mock import mock
24 + from unittest import mock
25 |
   |

UP026 [*] `mock` is deprecated, use `unittest.mock`
  --> UP026.py:27:1
   |
26 |   # Error (keep trailing comma)
27 | / from mock import (
28 | |     mock,
29 | |     a,
30 | |     b,
31 | |     c,
32 | | )
   | |_^
33 |   from mock import (
34 |       a,
   |
help: Import from `unittest.mock` instead
   |
26 | # Error (keep trailing comma)
   - from mock import (
   -     mock,
27 + from unittest.mock import (
28 |     a,
29 |     b,
30 |     c,
31 | )
32 + from unittest import mock
33 | from mock import (
   |

UP026 [*] `mock` is deprecated, use `unittest.mock`
  --> UP026.py:33:1
   |
31 |       c,
32 |   )
33 | / from mock import (
34 | |     a,
35 | |     b,
36 | |     c,
37 | |     mock,
38 | | )
   | |_^
39 |
40 |   # Error (avoid trailing comma)
   |
help: Import from `unittest.mock` instead
   |
32 | )
   - from mock import (
33 + from unittest.mock import (
34 |     a,
35 |     b,
36 |     c,
   -     mock,
37 | )
38 + from unittest import mock
39 |
   |

UP026 [*] `mock` is deprecated, use `unittest.mock`
  --> UP026.py:41:1
   |
40 |   # Error (avoid trailing comma)
41 | / from mock import (
42 | |     mock,
43 | |     a,
44 | |     b,
45 | |     c
46 | | )
   | |_^
47 |   from mock import (
48 |       a,
   |
help: Import from `unittest.mock` instead
   |
40 | # Error (avoid trailing comma)
   - from mock import (
   -     mock,
41 + from unittest.mock import (
42 |     a,
43 |     b,
44 |     c
45 | )
46 + from unittest import mock
47 | from mock import (
   |

UP026 [*] `mock` is deprecated, use `unittest.mock`
  --> UP026.py:47:1
   |
45 |       c
46 |   )
47 | / from mock import (
48 | |     a,
49 | |     b,
50 | |     c,
51 | |     mock
52 | | )
   | |_^
53 |   from mock import mock, a, b, c
54 |   from mock import a, b, c, mock
   |
help: Import from `unittest.mock` instead
   |
46 | )
   - from mock import (
47 + from unittest.mock import (
48 |     a,
49 |     b,
   -     c,
   -     mock
50 +     c
51 | )
52 + from unittest import mock
53 | from mock import mock, a, b, c
   |

UP026 [*] `mock` is deprecated, use `unittest.mock`
  --> UP026.py:53:1
   |
51 |     mock
52 | )
53 | from mock import mock, a, b, c
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
54 | from mock import a, b, c, mock
   |
help: Import from `unittest.mock` instead
   |
52 | )
   - from mock import mock, a, b, c
53 + from unittest.mock import a, b, c
54 + from unittest import mock
55 | from mock import a, b, c, mock
   |

UP026 [*] `mock` is deprecated, use `unittest.mock`
  --> UP026.py:54:1
   |
52 | )
53 | from mock import mock, a, b, c
54 | from mock import a, b, c, mock
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
55 |
56 | if True:
   |
help: Import from `unittest.mock` instead
   |
53 | from mock import mock, a, b, c
   - from mock import a, b, c, mock
54 + from unittest.mock import a, b, c
55 + from unittest import mock
56 |
   |

UP026 [*] `mock` is deprecated, use `unittest.mock`
  --> UP026.py:58:9
   |
56 |   if True:
57 |       if False:
58 | /         from mock import (
59 | |             mock,
60 | |             a,
61 | |             b,
62 | |             c
63 | |         )
   | |_________^
64 |
65 |   # OK
   |
help: Import from `unittest.mock` instead
   |
57 |     if False:
   -         from mock import (
   -             mock,
58 +         from unittest.mock import (
59 |             a,
60 |             b,
61 |             c
62 |         )
63 +         from unittest import mock
64 |
   |

UP026 [*] `mock` is deprecated, use `unittest.mock`
  --> UP026.py:69:8
   |
68 | # Error (`from unittest import mock`)
69 | import mock, mock
   |        ^^^^
70 |
71 | # Error (`from unittest import mock as foo`)
   |
help: Import from `unittest.mock` instead
   |
68 | # Error (`from unittest import mock`)
   - import mock, mock
69 + from unittest import mock
70 + from unittest import mock
71 |
   |

UP026 [*] `mock` is deprecated, use `unittest.mock`
  --> UP026.py:69:14
   |
68 | # Error (`from unittest import mock`)
69 | import mock, mock
   |              ^^^^
70 |
71 | # Error (`from unittest import mock as foo`)
   |
help: Import from `unittest.mock` instead
   |
68 | # Error (`from unittest import mock`)
   - import mock, mock
69 + from unittest import mock
70 + from unittest import mock
71 |
   |

UP026 [*] `mock` is deprecated, use `unittest.mock`
  --> UP026.py:72:8
   |
71 | # Error (`from unittest import mock as foo`)
72 | import mock as foo
   |        ^^^^^^^^^^^
73 |
74 | # Error (`from unittest import mock as foo`)
   |
help: Import from `unittest.mock` instead
   |
71 | # Error (`from unittest import mock as foo`)
   - import mock as foo
72 + from unittest import mock as foo
73 |
   |

UP026 [*] `mock` is deprecated, use `unittest.mock`
  --> UP026.py:75:1
   |
74 | # Error (`from unittest import mock as foo`)
75 | from mock import mock as foo
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
76 |
77 | if True:
   |
help: Import from `unittest.mock` instead
   |
74 | # Error (`from unittest import mock as foo`)
   - from mock import mock as foo
75 + from unittest import mock as foo
76 |
   |

UP026 [*] `mock` is deprecated, use `unittest.mock`
  --> UP026.py:79:12
   |
77 | if True:
78 |     # This should yield multiple, aliased imports.
79 |     import mock as foo, mock as bar, mock
   |            ^^^^^^^^^^^
80 |
81 |     # This should yield multiple, aliased imports, and preserve `os`.
   |
help: Import from `unittest.mock` instead
   |
78 |     # This should yield multiple, aliased imports.
   -     import mock as foo, mock as bar, mock
79 +     from unittest import mock as foo
80 +     from unittest import mock as bar
81 +     from unittest import mock
82 |
   |

UP026 [*] `mock` is deprecated, use `unittest.mock`
  --> UP026.py:79:25
   |
77 | if True:
78 |     # This should yield multiple, aliased imports.
79 |     import mock as foo, mock as bar, mock
   |                         ^^^^^^^^^^^
80 |
81 |     # This should yield multiple, aliased imports, and preserve `os`.
   |
help: Import from `unittest.mock` instead
   |
78 |     # This should yield multiple, aliased imports.
   -     import mock as foo, mock as bar, mock
79 +     from unittest import mock as foo
80 +     from unittest import mock as bar
81 +     from unittest import mock
82 |
   |

UP026 [*] `mock` is deprecated, use `unittest.mock`
  --> UP026.py:79:38
   |
77 | if True:
78 |     # This should yield multiple, aliased imports.
79 |     import mock as foo, mock as bar, mock
   |                                      ^^^^
80 |
81 |     # This should yield multiple, aliased imports, and preserve `os`.
   |
help: Import from `unittest.mock` instead
   |
78 |     # This should yield multiple, aliased imports.
   -     import mock as foo, mock as bar, mock
79 +     from unittest import mock as foo
80 +     from unittest import mock as bar
81 +     from unittest import mock
82 |
   |

UP026 [*] `mock` is deprecated, use `unittest.mock`
  --> UP026.py:82:12
   |
81 |     # This should yield multiple, aliased imports, and preserve `os`.
82 |     import mock as foo, mock as bar, mock, os
   |            ^^^^^^^^^^^
83 |
84 | if True:
   |
help: Import from `unittest.mock` instead
   |
81 |     # This should yield multiple, aliased imports, and preserve `os`.
   -     import mock as foo, mock as bar, mock, os
82 +     import os
83 +     from unittest import mock as foo
84 +     from unittest import mock as bar
85 +     from unittest import mock
86 |
   |

UP026 [*] `mock` is deprecated, use `unittest.mock`
  --> UP026.py:82:25
   |
81 |     # This should yield multiple, aliased imports, and preserve `os`.
82 |     import mock as foo, mock as bar, mock, os
   |                         ^^^^^^^^^^^
83 |
84 | if True:
   |
help: Import from `unittest.mock` instead
   |
81 |     # This should yield multiple, aliased imports, and preserve `os`.
   -     import mock as foo, mock as bar, mock, os
82 +     import os
83 +     from unittest import mock as foo
84 +     from unittest import mock as bar
85 +     from unittest import mock
86 |
   |

UP026 [*] `mock` is deprecated, use `unittest.mock`
  --> UP026.py:82:38
   |
81 |     # This should yield multiple, aliased imports, and preserve `os`.
82 |     import mock as foo, mock as bar, mock, os
   |                                      ^^^^
83 |
84 | if True:
   |
help: Import from `unittest.mock` instead
   |
81 |     # This should yield multiple, aliased imports, and preserve `os`.
   -     import mock as foo, mock as bar, mock, os
82 +     import os
83 +     from unittest import mock as foo
84 +     from unittest import mock as bar
85 +     from unittest import mock
86 |
   |

UP026 [*] `mock` is deprecated, use `unittest.mock`
  --> UP026.py:86:5
   |
84 | if True:
85 |     # This should yield multiple, aliased imports.
86 |     from mock import mock as foo, mock as bar, mock
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: Import from `unittest.mock` instead
   |
85 |     # This should yield multiple, aliased imports.
   -     from mock import mock as foo, mock as bar, mock
86 +     from unittest import mock as foo
87 +     from unittest import mock as bar
88 +     from unittest import mock
89 |
   |

UP026 [*] `mock` is deprecated, use `unittest.mock`
  --> UP026.py:93:5
   |
92 | # Error (`mock.Mock()`).
93 | x = mock.mock.Mock()
   |     ^^^^^^^^^
   |
help: Replace `mock.mock` with `mock`
   |
92 | # Error (`mock.Mock()`).
   - x = mock.mock.Mock()
93 + x = mock.Mock()
   |
