Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8511241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:56:06+00:00 2026-06-11T03:56:06+00:00

I must say I am new to python mock . I have an side_effect

  • 0

I must say I am new to python mock.
I have an side_effect iterator:

myClass.do.side_effect = iter([processStatus, memoryStatus, processStatus, memoryStatus, processStatus, memoryStatus, processStatus, memoryStatus])

The above works as expected and the test cases pass

But I am looking for a better way to write this.
I tried [....]*4 which did not work.

How should I do it? Simply, making the iterator to start from the beginning once it come to the end.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:56:07+00:00Added an answer on June 11, 2026 at 3:56 am

    I think you can use itertools.cycle here, if you want ‘over and over again’:

    >>> s = range(3)
    >>> s
    [0, 1, 2]
    >>> from itertools import cycle
    >>> c = cycle(s)
    >>> c
    <itertools.cycle object at 0xb72697cc>
    >>> [next(c) for i in range(10)]
    [0, 1, 2, 0, 1, 2, 0, 1, 2, 0]
    >>> c = cycle(['pS', 'mS'])
    >>> [next(c) for i in range(10)]
    ['pS', 'mS', 'pS', 'mS', 'pS', 'mS', 'pS', 'mS', 'pS', 'mS']
    

    Or, as @mgilson notes, if you want a finite number of 2-element terms (I’m not completely sure of what data format you need):

    >>> from itertools import repeat
    >>> repeat([2,3], 3)
    repeat([2, 3], 3)
    >>> list(repeat([2,3], 3))
    [[2, 3], [2, 3], [2, 3]]
    

    But as noted in the comments, iter([1,2,3]*n) should work too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First I must say that I'm not good at English and completely new to
One can say a type parameter T must have a specific supertype S_1: class
I have a conceptual Python design dilemma. Say I have a City class, which
I must say I am quite new at WPF. I am building my first
I've been learning Python and I must say I loved it. But as a
Say I have two tables. new_dogs and name_color_pairs. The records in name_color_pairs must be
Hi there First of all just let me say that I'm new in Python
i must say im new to win32 c++ programming so i face a problem
I'm new to LaTeX and I must say that I am really struggling with
First of all, I must say that I am quite new to the API

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.