As with all things it really depends on the situation. Many variables need to be taken into account in order to determine if it is right play or not. These include the size of the pot, you and opponent stack sizes, you and your opponent table image, the actual board and your hand and time of tournament if it is a mtt or sng.
Example 1 cash game you have 80BB pot is 10BB you bet 5BB and a tight player raises you all in you should fold. Not getting right odds and tight players usually have very strong
hands when they go all in.
Example 2 cash game you have 25BB pot is 10BB aggro player cbets 5BB like he always does board is Jh 10h 5d you have AQh. Not only do you have nut flush draw but 2 over cards to the board and a gut shot to the nut straight. I would raise all in here, opponent is aggro he may have nothing and fold even if he has top pair and call you a slight favourite to win pot.
Example 3 mtt you have 40BB pot is 10BB you have Qh 10d board Ah 8h 4h. You opponent is relatively solid player 5 players to go until you reach itm there are 10 small stacks of less than 10BB. Opponent bets pot (10Bb) on flop you call turn 5Q and your opponent put you all in. You fold here.
Reasons why to fold here:
-you could be drawing dead if opponent has nut flush already or has AK with Kh
-if opponent has nut flush draw you are drawing to 5 outs so not getting correct odds
-if your flush draw is live you are still not getting correct odds
-there are smaller stacks that would likely bust soon you can simply fold and make itm
You can use the odds calculator here to runs some different examples and see how likely a flush draw or any hand is to win a hand
https://www.cardschat.com/poker-odds-calculator.php
You can also go to this section
https://www.cardschat.com/poker-strategy.php
There is a section called the "The Math of Poker" There are 5 links in that section all 5 contain valuable information about odds,
equity and
expected value. By learning these you will understand the odds and how to use this as part of the decision making on when to call or fold and most importantly why to do so.