This is one of the lessons I teach about in my workshop (see link in my signature below). There are specific exercises you can do to improve your ability to assess colors accurately, and there are ways to approach your painting’s workflow so you don’t even have to worry about this at all, as you’d be using a much more logical approach to color variations in your artwork.
What’s really important, more than anything else, is the way you think about color. In order to gain a strong grasp on colors, you have to think about them very logically, such as the effects of radiosity and how color bleed from bounced light changes the colors of surfaces they bounce onto. There’s also the natural variations that happen to the local colors themselves, such as how skin tone has warmer, more flushed areas with lots of micro blood vessels, as well as cooler areas where there’s a lot of fat and bone under the skin. There’s of course also the color cast of the light sources themselves and now they alter the colors of everything they illuminate. And once you’ve got a good handle on the logical aspects of lighting and colors, you can exert artistic license and alter the colors specifically for artistic effect. but usually you only push the colors that far in images that are meant to be very stylized, where the color choices no longer conform to the laws of physics (for example, using lots of vivid colors to paint a stylized, surreal-looking portrait, but none of those colors actually exist in the real-life counterpart).
When you are able to approach colors logically, it’s mainly just a matter of matching the colors to the laws of physics so they visually make sense (which often also means they look sophisticated and convincing). When thinking that way, you’re not concerned with whether you can easily identify/choose a color even when the surrounding colors are causing optical illusions and throwing you off. What you’re thinking about instead, is how that wall, which is painted blue, is bounding its color onto that red shirt, and mixing the blue with the red to create purple, but there’s also a yellow light source that’s also adding to the mix, further changing the color. If you paint with that logical approach and use the correct workflow (local colors first, light source color cast influence next, radiosity/color bleed next), you won’t have to worry about the stuff you asked. I explain all of this is far greater detail in the workshop.