How to derive the binomial test? From what I understand from a pervious question I asked, the p-value for a particular binomial test (specifying a number of flips, and number of heads and tails, and a null-hypothesis to test against) loosely describes the probability that this data is expected with the assumption that the null-hypothesis is correct.
So if I do a binomial test for binom_test(numberOfHeads=9, numberOfFlips=10, weight = .5), and obtain a pvalue for the 2-tailed test. This represents the probability that such an event (nine heads in 10 flips) could occur by a fair coin. If this number is very small, then we can assume that the null hypothesis is rejected with some level of statistical confidence.
My issue is that I'm having a lot of trouble understanding what the derivation of the binomial test. In python there is a binomial test function, but they simply link to the wikipedia article on binomial test.
Intuitively if my null hypothesis is p=1/2, shouldn't my binomial test just be the binomial distribution? For example, I would have thought that my pvalue getting 4 heads in 5 flips would be just the probability of a fair coin getting 4-heads in five flips. So  ${5 \choose 4} (1/2)^4(1/2)^5$. Is this correct? I am looking at what is done on wikipedia and it doesn't seem as though it's in agreement with my thoughts - but what they have written (particularly for the two tailed test) is very unclear to me.

Thanks to @BruceET and @Glen_b some confusion was clarified, which I figured I'd write here to be helpful for anyone who also had my issue.
The main issue that I had was that I previously did a simulation to look at the frequency at which fair coins produce p-values that would be false-positives.
If I have a p-value of 3.4% and test it for p-value<3.5% (some interval that compensates for the discrete nature), this 3.4% doesn't mean that there is a 3.4% chance of reproducing the same data, but instead is that there is a 3.4% chance that a fair coin with that data would produce a p-value of 3.4%.
What was hard for me to understand, after getting that idea, is that this p-value seems like just an arbitrary function, and we could've used any function and characterized the chance said data would produce a certain output for that function.
But, from what I'm gathering, the utility of the p-value is that it typically adds a weight to all unlikely events. So you're sort of heuristically collecting all probabilities that are as and more unlikely in the parameter of interest and adding them up. Not quite at 100% understanding (and please correct me in the comments), but I think I am at least more correct than I was.
